4,305 Posted Topics
Re: On the issue of code you can understand and is therefore Pythonic, your first code ... [code]def LeapYear(year): if year % 400 == 0: return True elif year % 100 == 0: return False elif year % 4 == 0: return True else: return False [/code]Follows the leap-year rule clearly … | |
Re: A dictionary consists of key:value pairs. The keys have to be unique. If you had for instance this dictionary: [code]d = {'abc': 1, 'Abc': 2, 'abC': 3}[/code] Now suddenly you set the key to all lower case, which associated value to you really want? | |
Re: Yes, it still functions, but one will prompt [B]please enter number 1:[/B] [B]please enter number 2:[/B] ... and so on and the other just [B]please enter number:[/B] [B]please enter number:[/B] ... and so on | |
Re: [QUOTE=liquidroof;1218741]Thats really good to know, congrats and keep moving.[/QUOTE] Well, it gave this signature spammer a chance to peddle his/her leaky roof products! | |
The Python module 'tarfile' is more flexible then it's counterpart 'zipfile'. It allows you to simply archive files without compression, or use the gzip format of compression, or the super compression format bzip2. Here is code to show you the use of the module. | |
Re: If you want to display and later retrieve results from a Tkinter GUI, it would be better to use the Text widget rather than the Label widget. The Text widget is a little more complex, but amongst the many things you can do with it, is the retrieval of the … | |
Re: When you use [B]self.var = IntVar()[/B] you are really creating an instance of a class this class has [B]get()[/B] and [B]set()[/B] methods | |
Re: Here would be another approach ... [code]# change start and ending to test link = "mailto ---- pdf" # startswith conditions start = ('javascript','mailto') # endswith conditions end = ('pdf','ppt') if not all( (link.startswith(start), link.endswith(end)) ): # do something print("link = %s did not pass" % link) else: print("link = … | |
Re: You can expand on something simple like that ... [code]''' contents of data_file_1.txt --> Fred, Nurke, 16, 17, 22 Jack, Sprat, 12, 13, 19 George, Reynolds, 14, 11, 30 Harry, Smith, 19, 19, 37 Daniel, Robins, 10, 8, 22 Jacquiline, Stevens, 23, 18, 31 Erin, Collins, 24, 30, 35 William, … | |
Re: Rewrite you code this way to make the import global ... [code]from PIL import Image def bw_negative(filename): """ This function creates a black and white negative of a bitmap image using the following parameters: filename is the name of the bitmap image """ # Create the handle and then create … | |
Re: Nice program indeed! On Windows it was a little cumbersome to get the wxPython support. I had to go through the following sequence ... I had to first install wxFormBuilder_v3.0.57.exe and then extract wxAdditions_Plugin_v1.07.zip into that directory Then install this over the older version wxFormBuilder_v3.1.61-beta.exe (since that one had a … | |
![]() | Re: Get involved with the speech engine built into Windows XP. It allows you to read text in several different voices. BTW, it is real fun to have the German or French guy read English text. I am trying to write a simple slide viewer that reads a description to each … |
Re: You really have to wait till some of the bigger states like California, Texas or New York come into play. Now you are talking convention delegates. Sorry, but Iowa and New Hampshire have really insignificant populations. | |
Re: BeautifulSoup is a third party module for Python2 that allows you to access even badly coded HTML code. What do you want to do with it? | |
Re: A program that leaves programming to the computer. This way we wouldn't have to put up with these self-important odd balls that spend hours arguing how many pointers it takes to move a text from from one function to another. | |
Re: [QUOTE=nbrmkumaresh]Please give me an idea of how to do program the huffman code in C[/QUOTE] Check the C code snippet right here on DaniWeb: [url]http://www.daniweb.com/code/snippet5.html[/url] Test it, improve it, learn from it! | |
Re: Try something like string formatting ... [code]myvalue = 16 # %02x creates a 2 digit hex byte padded with zero if needed command2 = r"\x03\xa2\x%02x" % myvalue print command2 # \x03\xa2\x10 [/code] | |
Re: Here is a Python module turtle example of how to draw two concentric circles ... [code]import turtle as tu # initial radius radius = 100 # distance between circles distance = 30 # pen up tu.up() # move pen to point x, y # keeps the center of the circle … | |
Re: Python is an [B]interpreter[/B] and only compiles to it's internal byte code. Packagers like [B]py2exe[/B] are available that package the byte code and the interpreter (dll) into a self-extracting executable file. | |
Re: Of course, you simply move the find() start position up as you search ... [code]# multiple searches of a string for a substring # using s.find(sub[ ,start[, end]]) text = 'MSKSASPKEPEQLRKLFIGGLSFETTDESLRSAHFESSSYGSAGRRF' search = 'SA' start = 0 while True: index = text.find(search, start) # if search string not found, find() … | |
Re: Please show us your code. On line 33 you have "del lib", you are trying to delete an object called "lib" that is not there. | |
Re: I think you can buy it frozen and stick it into the microwave. | |
Re: Stereotype? Except for the pink Net-book all of our Computer Engineers look like that. :) | |
Re: Enlighten us a little ... What is protege? What is owl ontology? What does a short sample of the raw data look like? | |
Re: Interesting, you must have hit a gap in the algorithm. I tested it out and came up with these results ... [code]# numpy.random.hypergeometric(ngood, nbad, nsample, size=None) import numpy as np # these work fine print np.random.hypergeometric(10000, 10000, 10000) print np.random.hypergeometric(100000, 1000000, 100000) print np.random.hypergeometric(10000000, 1000000000, 1000000) # these freeze up … | |
![]() | Re: You get the error because you are using submenu in line 16, but create it in line 25. |
Re: You can also check the Python module [B]difflib[/B] for line to line comparison of two different texts. | |
Re: Code snippets are for working code only! Place questions in the regular Python forum! It's taken care of already, thanks! | |
Re: You really don't want to create a new label every time you click. | |
Re: This would be a simple search in a nested list, but this approach has certain caveats ... [code]mylist = [['dog', 'cat'], ['lizard', 'sheep', 'pig']] print( "'sheep'" in str(mylist) ) # True [/code] | |
Re: There are some huge IDEs like Eclipse with pydev, or Netbeans for Python. They however are very sluggish and force you to create a project for even the smallest test file. Eric isn't quite as sluggish. I like the fast and nimble IDEs like PyScripter (Windows only), DrPython (only for … | |
Re: Simpler ... [code]if x in List: # do something with x [/code] | |
Re: Here is one way to do this ... [code]# a simple sign using wx.richtext.RichTextCtrl() import wx import wx.richtext as rt class MyFrame(wx.Frame): def __init__(self, parent, mytitle, mysize): wx.Frame.__init__(self, parent, -1, mytitle, size=mysize) self.SetBackgroundColour("white") rich = rt.RichTextCtrl(self, -1, value="") # default is black text rich.BeginFontSize(26) rich.BeginBold() rich.WriteText(" You are in ") … | |
Re: Make the min_item the first item in the list. Then iterate through the list and compare. If the list item is less than the present min_item, make it the new min_item. Do a similar thing with max_item. | |
Re: Here I used a basic Tkinter class template to test your method createEight(self) and gave the button a command ... [code]# Tkinter class template to test apps try: # Python2 import Tkinter as tk except ImportError: # Python3 import tkinter as tk class MyApp(tk.Tk): def __init__(self): tk.Tk.__init__(self) self.title("Tkinter basic class") … | |
Re: You can use Python's regular expression module re, very powerful for text processing, but there is a somewhat steep learning curve ahead! [code=python]# exploring Python's regular expression module re import re # find all upper case letters in a text: text = "This text has Upper and Lower Case Letters" … | |
Re: The way a binary system like a computer represents a decimal or floating point number can create a tiny difference that makes it hard to compare floats directly. All computer languages have this problem, and beginners just love to stumble over it. To illustrate this ... [code]def fuzzy_compare(a, b, delta=0.000000001): … | |
Re: It's not even April first yet! | |
Re: If your string is just a single word like [B]"racecar"[/B], then you can simply compare the string with it's reverse spelled counterpart. If your string is a complete sentence like [B]"A man, a plan, a canal, Panama!"[/B], then you should turn all characters to lower case, remove the punctuation marks … | |
Re: Let's say your array of measured voltages would be a list (Python's version of an array) like this ... voltage_list = [105, 108, 111, 117, 109, 112] The size (number of voltages in the list) of the voltage list is ... size = len(voltage_list) Also let's say your action potential … | |
Re: Quit will quit the tcl interpreter of Tkinter! If IDLE is used, quit will freeze it, since IDLE uses Tkinter too! Replace quit with destroy, destroy is used to destroy a particular window in a multi-window program | |
A short look at creating lists of file names or full path names using the versatile Python module glob. Glob follows the standard wildcard protocol. | |
Re: You can also use something like [B]time.sleep(10) root.update()[/B] instead of [B]root.mainloop(0)[/B] | |
Re: Like IsharaComix pointed out, this is not very useful ... [code]# add a key/variable to the local dictionary vars() # can be done, but not very useful mylist = [0, 1, 2, 3, 4] n = 1 for item in mylist: # add variable names t1 to t5 vars()['t'+str(n)] = … | |
Re: camigirl4k3, you got to learn to use the necessary indentations with your statement blocks. | |
Re: Here is a function that will check for valid numeric input ... [code]# a simple input function to guarantee numeric input # tested with Python 3.1.2 def input_num(prompt="Enter a number: "): """ prompt the user for a numeric input prompt again if the input is not numeric return an integer … | |
Re: You can really simplify and make your animation much smoother using canvas.move() rather then erase and redraw your canvas shapes. Here is a typical example ... [code]# Tkinter animate via canvas.move(obj, xAmount, yAmount) # tested with Python 3.1.2 import time import tkinter as tk root = tk.Tk() canvas = tk.Canvas(root, … | |
Re: Actually functions any() and all() where introduced with the advent of Python 2.5. Here is a little test ... [code]# Guido proposed boolean functions any() and all() for Python25 # and higher, tested with PortablePython 2.5.4 # combine with generator expressions like this ... seq = (11, 23, 45) # … | |
Re: Please be more descriptive with your thread's title. It gets a little confusing with two of the same titles. | |
Re: The problem with the livewires wrapper is that it is rather old and updates are spotty. You would be much better off and learn more using PyGame directly. |
The End.