2,190 Posted Topics
Re: You can read the data into a list. As stated above, the following statement is already a list, so no need for the copy. fdata = open(vhdat).readlines() If there are 544,000 recs and each rec is 100 bytes, that is 54,400,000 bytes (54 megs) of memory. That's very doable in … | |
Re: Install Tile. Google will give a lot of results about Tile improving Tkinter. Also, try other fonts. I like linux-libertine. This will list the fonts that are available. [CODE]from Tkinter import * from tkFont import families import Pmw root = Tk() Pmw.initialise() choice = None comboentries = families(root) ##--- Move … | |
Re: First you have to define "equal". If it means any difference at all then first, see if the two files have the same length. If not, then they are not equal, If they are the same length, open each one in binary mode and read a fixed number of bytes … | |
Re: Another threading tutorial [url]http://blog.doughellmann.com/2008/01/pymotw-threading_13.html[/url] but you probably should be using something like pygame. | |
Re: It's late and I'm tired but this is the general idea if I understand correctly[CODE]data=["1lghB A i 79.8 H H -24.58", "1lghB V i 79.6 H H -22.06", "1lghB H i 71.9 H H -19.94"] for line in data: print "\nlooking at", line substrs=line.strip().split() print "amino acid =", substrs[1], "and … | |
Re: I usually use a dictionary or list[CODE]self.input_score_dic={} for m in range(1, 10): self.input_score_dic[m] = Entry(frame,width=6)[/CODE] | |
Re: You are only checking the first record since you only do one readline(). Add some print statements after the while loop so you can see what you are looking through. If you use readlines(), the entire file will be read into a list[CODE]fp = open(modelfilename) data = fp.readlines() fp.close() for … | |
Re: Perhaps you should state why you want to go around pinging sites. os.popen() is probably not the right tool but that depends on what you are trying to do. | |
Re: Look at the info on control variables here. You will probably use .set() to set the contents of the entry widget. If you still can't get it to work, post some specific code. [url]http://infohost.nmt.edu/tcc/help/pubs/tkinter/control-variables.html[/url] | |
Re: Add some print statements so you can tell what is going on, such as[CODE] convert_table = {1:{0:0}, 2:{0:1}, 3:{0:2}, 4:{1:0}, 5:{1:1}, 6:{1:2}, 7:{2:0}, 8:{2:1}, 9:{2:2}} yx = convert_table[3] print yx, type(yx)[/CODE]There isn't a y, x in yx (convert_table[choice]). It's a dictionary not a list. You'll have to use something else … | |
Re: Google for "convert 'base 16'" which will hit on general conversions also. The math is straightforward and on a lot of sites, as well as how letters are used. | |
Re: Bash will do that for you In Linux. You can also use sys.stdout.write(sys.stdin.read()), although subprocess is now the preferred method. I would guess that on other operating systems it would also be subprocess. This is Doug Hellman's module of the week on subprocess which should get you started [url]http://blog.doughellmann.com/2007/07/pymotw-subprocess.html[/url] | |
Re: Use the show="*" attribute. Also, you are not getting any responses because a Google for "tkinter password" will yield more hits than you can deal with. If this isn't homework, use something found on the web that has already been tested (and is probably written by someone with more Tkinter … | |
Re: Don't know if you are aware of Python's webbrowser class. It allows you to display web-based docs, etc. You can choose a particular browser or use the default browser. I don't know if it will tell you what the default browser is though. | |
Re: AFAIK you use the Python Imaging Library [url]http://www.pythonware.com/library/index.htm[/url] Perhaps someone else will know more. | |
Re: It's not possible to tell without a line number for the error. I do see that there isn't a comma after overtime in this line print "You earned", pay, "regular pay and", overtime "overtime pay which is a total of", totalpay | |
Re: Use endswith. fnmatch is specific to *nix (I think) and so won't work if you are using MS Windows.[CODE]if os.path.isfile(fullname): # Only work on VOBs and MPGs (for now) if filename.endswith('.vob') or filename.endswith('.mpg'): f.write('dgindex.exe -IF=[%s] -FO=0 -OM=0 -OF=[%s] -MINIMIZE -EXIT \n' % \ (fullname, fullname)) ## ## You could also … | |
Re: For viewing and editing, try passing data to TableListWrapper, [url]http://tkinter.unpythonic.net/wiki/TableListWrapper[/url] The edittest() function is the one to try. | |
Re: Just to be complete, BLT adds graphing to the TCL/Tk toolkit. Use whichever of the suggestions seems best to you. They will all work. [url]http://incrtcl.sourceforge.net/blt/[/url] | |
Re: [QUOTE]Actualy that didnt work. I changed the statements to if sex == "M" or "m":[/QUOTE]An if() statement with an "or" is the same as two if statements (or an elif), so the above equates to if sex == "M": elif "m": I think you want --> if sex=="m" "if m" … | |
Re: Use string.find[CODE]## This code assumes that "blah is always in the string before "notblah" ## and that the sequence is "blah" then "notblah" and not some variation ## of "blah", "blah", "notblah" some_string="ab-blah-cde-notblah-fghij-blah-klm-notblah-no-blah-stu-notblah-xyz" result=0 while result > -1: ## -1 = not found result=some_string.find("blah", result) result2=some_string.find("notblah", result+1) if (result > … | |
Re: [CODE]while y < (t - 1): if y == t:[/CODE] Note that (t-1) < t, so y is always less than t and the if() portion will never be executed. You can also use a for loop[CODE]t = len(myint) ##while y < (t - 1): for y in range(0, t): … | |
Re: Reverse the two for() statements so you only read the file once (and don't use i, l, or o as variable names. They look like numbers).[CODE]for line in f: for j in scorelist if j in line: print j score = score + 1[/CODE] | |
Re: If the file has Python code, then it should end with a ".py" not ".txt". If it is not a Python file, but a file with text you want to read in the program then you open the file and read it. See #6 here for how to open and … | |
Re: [QUOTE]Program should accept a file name as input[/QUOTE]Do you want the program to ask the user to key in a file name, or do you want to provide it as an argument when the program is called, or do you want to use a GUI that allows the user to … | |
Re: You will have to use unicode strings. Here is Guido's tutorial [url]http://docs.python.org/tut/node5.html#SECTION005130000000000000000[/url] From the tutorial, you would use word=u"3ÇáäÃÇÈÉ".encode('utf-8') if arabic uses 8 bits per byte. | |
Re: One comment first. You have 2 redundant lines in the original code[CODE]n = int(input("Give me an integer: ")) list1 = [] ##i = 1 ## this line is redundant-the for() loop handles initializing i for i in range(1,n+1): print "i =", i ## this will show what the for() loop … | |
Re: You will likely want to use a Tkinter StringVar() with the .get() to get the contents of the entry box. If memory serves - a Google for "Tkinter StringVar Entry" will yield thousands of hits as well var = Tkinter.StringVar() entry_box = Tkinter.Entry(frame_name, width=5, textvariable=var) python_var=var.get() [Under def playCk(self): for … | |
Re: "return prime" is not indented correctly. For the "print a message if the number isn't even" you already test for even with if n % 2 == 0: ## even . else: ## not even #do what you want here for numbers that aren't even Note that 5 is not … | |
Re: You can also use a function. Also you calculate math.sqrt(n) on every while loop. Once is enough.[CODE]import math def test_for_prime(n): n = abs(n) j = 2 stop=math.sqrt(n): while j <= stop: if n % j == 0: return False j += 1 return True if __name__ == "__main__": print "This … | |
Re: Note the number of times you have "ord(letter) + rotate". A little algebra[CODE]## substituting ascii_val for ord(letter) + rotate def rotate_word(s,num): rotate = num % 26 newword = ' ' word=s.upper() for letter in word: if ascii_val > 90: ## ascii_val doesn't exist; this is just for demonstration ascii_val = … | |
Re: if count <= count1: Is count1 delared somewhere? If so, which line is the error referencing. Also, use CODE tags, see this post [url]http://www.daniweb.com/forums/announcement114-3.html[/url] | |
Re: Not very elegant, but try to do anything within a try/except?[CODE]try: Tkinter.Label(root).pack() except: print "No window exists" ## Edit: Modifing a well known label example ## Uncomment the root.destroy() line from Tkinter import * root=Tk() def changeLabel(): myString.set("I'm, a-fraid we're fresh out of red Leicester, sir. ") ##root.destroy() try: label2=Label(root).pack() … | |
Re: Without the lambda (which you probably haven't covered)[CODE]input_str=raw_input("Enter a string of digits ") ##-------------- Simple way -------------------------------------------------- input_list = [int(x) for x in input_str] print sum(input_list), input_list ##-------------- Check that it is a digit and sum manually ------------------- input_list=[] errors=0 for chr in input_str: if chr.isdigit(): input_list.append(int(chr)) else: print "Only … | |
Re: Take your first post and apply the same logic to both strings, phonebook and inp (for individual character in string). I think you can do the averages, etc.[CODE]inp = (raw_input('Input: ')) phonebook = 'bcdfghjklmnpqrstvwxyz' for ip_char in inp: found = 0 ## reset these variables for each letter in inp … | |
Re: I use easyGUI for quick and dirty apps [url]http://www.ferg.org/easygui/[/url] | |
Re: Not sure what you are asking but try this and see if it helps any. You have to test each individual character and replace the ones that match your criteria. [CODE]for line in self.map: ## one line at a time spaces="" ## move each character over one space for character … | |
Re: Also you only add 12 to the hour if it is 1:00pm through 11:00pm. | |
Re: The problem is line 2 fin = open ('E:/words.txt') You open the file as a global and in line 23 process each record in the file via a for() loop, leaving the pointer at the end of the file. So the second time through you read the file starting at … | |
Re: Are you using Samba to connect to MS files? It seems no one here uses unixODBC 2.2.12 or FreeTds 0.64, so you might have more luck asking on the mailing list/forum for those programs, especially since it has to do with ini files and not python. | |
Re: To print directly to the printer, you have to access the device driver. I'm on linux so can't help you there. A more common method for simple files that do not have to be formatted is to write the output to a file and use os.system() or subprocess with a … | |
Re: There is a slight flaw in ZZucker's post, but the OP should have reason this out for themselves. | |
Re: The assignment says "For a number n, this function determines all factors of n and returns these factors as a list" so I would assume that the number 54 would return (2, 3, 6), and their other half (27, 18, 9) as a list, meaning the program would want to … | |
Re: Setting a path is OS dependent. In Linux you should be able to use os.system( "export NEWPATH" ) although I haven't tried it. If you want to import a module that is not in your PYTHONPATH then you can use sys.path.append(). Almost every tutorial covers this. | |
Re: You can split on the "#" and do a single replace for both characters if that helps That's a single pass through the number string for the split() and a single join to put it back together instead of multiple lookup passes to find and replace each number. Instead of … | |
Re: Obviously exp() can't use an array as input. This makes sense. I suggest you ask this question on the Numpy board. People there will have more info on how/if you can use an array. | |
Re: Do you mean the earliest and latest times for one day in the file. That should be fairly straight forward. min_time=99:99 max_time=00:00 if time < min_time: min_time=time (you will actually have to convert to minutes) elif time > max_time: max_time=time Of course you will have to test for date != … | |
Re: Print tl, tu, & tm. That should give you some ideas. You might want to use datetime instead or convert everything to seconds.. [code]import datetime today=datetime.datetime.now() midnight = datetime.datetime(2008, 2, 25, 0, 0, 0) if today > midnight: print "today is greater", today, "-->", midnight else: print "midnight is greater" … | |
Re: Using a for loop might be easier to understand.[CODE]test_list=[1,3,5,7] ctr = 0 stop=len(test_list) for j in range(0, stop): ctr += 1 before_add = test_list[j] test_list[j] += ctr ## ctr = j+1 in this specific case print "element", j, "did =", before_add, "and now =", test_list[j] print "\n", test_list[/CODE] | |
Re: Try a print str(unicode_string_var) This is assuming that all characters in the variable can be displayed for your locale. |
The End.