2,190 Posted Topics
Re: The above code doesn't strip the newline so you want to use .strip() as well. If the file contains multiple "geneX" codes, you want to append the records to a list until the next "gene" is found. When found, send the list to a function that will concatenate, similiar to … | |
Re: os.system("cd \..\Program Files\Mozilla Firefox\ Start firefox.exe") "cd" = change directiory. You want to execute the program which you should be able to do by calling it from os.system() os.system("\..\Program Files\Mozilla Firefox\ Start firefox.exe") Check this directory to make sure you want to call "Start firefox.exe" instead of "firefox.exe" or "/Start/firefox.exe". … ![]() | |
Re: You can find an ordered dictionary here [url]http://www.voidspace.org.uk/python/odict.html[/url] but that does not solve the "but then want _all_ messages with a higher ID" problem as you don't know what the next higher key is. A list of keys will return the index of the key found, and you can then … | |
Re: I think 'cut -d"_"' means split on the "_" which would be .split("_") in python but you will have to explain what the rest is. So first you want to post your code that opens the file and reads it one record at a time, and you should be able … | |
![]() | Re: When comparing two strings you want to make sure they are the same length. They will never be equal if they are different lengths, so add a statement which prints if they are not equal,[CODE]log_fp=open('log.txt','r') read_log=log_fp.read() while choice!=read_log: if len(choice) != len(read_log): print "choice length", choice, len(choice), \ "and read_log … |
Re: [QUOTE]I used: if (queryperson in population):[/QUOTE]Print the list "population" and see what it contains. | |
Re: [QUOTE]• Membrane that surrounds the heart a. somepossibleanswer b. somepossibleanswer c. somepossibleanswer d. somepossibleanswer e. correct answer f. somepossibleanswer > e Correct![/QUOTE]One way is to use 2 dictionaries. The first uses "membrane" as the key, pointing to a list with the possible answers. You print/display this list in the form … | |
Re: [QUOTE]What can I do to prevent using same roll for two stats?[/QUOTE]Append the random rolls to a list and use each value in the list once only. If I misunderstand and this is not what you want, then post back.[CODE]import random ## random can come up with the same number … | |
Re: [QUOTE]The aorkeys extract correctly,[/QUOTE]Assuming that this means that the list aorkeys contains all of the numbers that you want to find, and that it is not a huge list, it is easiest to look for each key in the list.[CODE]h = open(redFile,'w') g = open(orgFile,'r') #Search each entry in file.lst, … | |
Re: Tkinter's FileDialog is a easy way to select a file name. Double click to select a directory or file.[CODE]from Tkinter import * from FileDialog import FileDialog def GetFilename( dir = "" ): top = Tk() d = FileDialog( top ) fname = d.go( dir ) if fname == None : … | |
Re: If possible, set it up so you can call/execute the C functions using subprocess. See "Reading from the output of a pipe:" here [url]http://www.doughellmann.com/PyMOTW/subprocess/index.html#module-subprocess[/url] | |
Re: [QUOTE]how can I achive mutliple matches from a line in single if statement like I need to ignore a line that starts with '<' and ends either with '>' or ' ; '[/QUOTE]The simpliest way, without using and/or combinations, is to use an indicator which you set to True if … | |
Re: [QUOTE]TypeError: sequence item 0: expected string, list found[/QUOTE]It is very difficult to tell without knowing which line is causing the error. A guess would be this line o.write('\n'.join(temp)) as you are tyring to join a list of lists [from the split()] instead of one list. Try this instead (there is … | |
Re: [QUOTE]The outputs are excel based worksheets.[/QUOTE]If reading an Excel sheet will solve the problem, pyExcelerator is one way [url]http://sourceforge.net/projects/pyexcelerator[/url] | |
Re: Use a list for the correct responses within some kind of while loop[code=python]exit = False while not exit: #Limit the answer to a combination of r g b y o p colorCode = raw_input("Player 1 enter the secret code. No cheating player 2! ") if colorCode in ['r', 'g', 'b', … | |
Re: [QUOTE]On click of a button on frm1, I want frm2 to pop up and frm1 to hide.[/QUOTE]Use a normal function callback for the click on the button. The function will raise frm2 and/or lower frm1. How that is done depends on the toolkit you are using. Some sample code would … | |
Re: lsof will list all open files on the system and has many options for what is reported. See this page [url]http://www.ibm.com/developerworks/aix/library/au-lsof.html[/url] | |
Re: Try adding print statements to both functions. "None" means that no pattern match was found.[CODE]def find_name(): folder = "C:/Users/Sam/Desktop" for filename in os.walk(folder).next()[2]: print "testing filename", filename if pattern.match(filename): print "find_name returning", filename return filename def main(): newname = str(duration) + ".txt" filename = find_name() print "filename returned is", filename … | |
Re: First, what happens if maxSignalInDatasource == 1000? I changed the first if to <= 1000. Second, int(offsetX) does nothing, so that was changed to offsetX_int = int(offsetX). Third, the way you have the indents positioned in your post, everything from elif viewMaxSignal1 < 1000: and below will only be executed … | |
Re: Another idea. You can also split on the "AND" and then split on "|" removing the [-1] element.[code]test_input = "AND Category 07|Spec 01|ABC 01 AND Category 07|Spec 02|XYZ 02 AND Category 07|Spec 03|PQR 03 " after_and_split = test_input.split("AND") print after_and_split new_str = "" for str in after_and_split: after_line_split = str.split("|") … | |
Re: Please don't spam this site or someone will report you and you will be banned. Since the OP didn't say which toolkit or OS was involved, it is obvious that there is no way to recommend anything, hence MESHIKUMAR and mohankumar554 are the same and are spamming. | |
Re: You read it one line at a time, but write only if the counter is between the numbers. And don't use "i", "l", or "o" as single variables because they look too much like numbers.[CODE]f = open(infile,'r') o = open(outfile,'w') ctr = 1 for line in f: if first <= … | |
Re: [QUOTE]I'm doing a project doing atomic models and am using a toolkit that was developed for Python 2.4 on Ubuntu[/QUOTE]That toolkit should run under 2.6 even though it was developed using 2.4, so your first option is to try running it using 2.6. /usr/bin/python should point to python2.6 somewhere on … | |
Re: If you are using a normal flat file instead of pickling, you can only store strings. While you can use writelines for writing a list, I would suggest that you write to the file in a format that you understand, so you can read it back into a program as … | |
Re: These are the rpms for 2.3 on the Python web site. I would install all 5 of them just to be safe. [url]http://www.python.org/ftp/python/2.3/rpms/redhat-9/[/url] If you can step up to 2.5, then try Active State's version, as they have everything bundled with it. | |
| |
Re: This is the Python forum. Try the MySQL forums. [url]http://www.daniweb.com/forums/forum126.html[/url] [url]http://forums.mysql.com/[/url] | |
Re: You want to add a print statement to see what is going on[CODE] exact = 0 while (exact != 4): userGuess = guess.askForGuess() exact = exactMatchCount.exactMatch(userGuess,secretCode) print "exact =", exact if exact != 4: print "Another while loop is necessary\n" partial = partialMatchCount.partialMatch(userGuess,secretCode) print "Black pegs: " + str(exact) print … | |
Re: [QUOTE]Ugh I hate these elif errors![/QUOTE]Then don't use it. Some examples that also simplify the code. [CODE]## instead of if line == 0 ,1 2, etc. for line in f: if (line > -1) and (line < 10): row0.extend([line[x] for x in range (0, 10)]) ## ##------------------------------------------------------------------ """ #the initial … | |
Re: This is the only one that I know of, although I think there is something that uses ncurses as well. Also, you want double equals here if x == "w", and if you have a lot a compares, you can use a dictionary with the function name, or the print … | |
Re: [QUOTE]I want it to sort both the map name and the map index though should I use a dictionary instead?[/QUOTE] If you want to look up the name or index then use one dictionary for each, unless there is a very large data set. If you want to sort and … | |
Re: Running the following code yields the result posted. id is one of the first things you want to know when two objects appear to be the same.[CODE]f = FD_field(4, 4, 4) f.At(1, 1, 1) print ("f #1 id = %d" % id(f.data)) f.Set(1, 1, 1, 5) f.At(1, 1, 1) print … | |
Re: One of you should have just written the entire program in the beginning, since the OP didn't have to produce even one line of original code, and saved everyone the trouble of having to read through all of the posts. | |
Re: [quote]I keep getting an error that says Im giving it more arguments than it can take.[/quote]You are sending player1 and player2 to the class, but don't have arguments for them. If that doesn't answer your question, then post back.[code=python]class Application(Frame): def __init__(self, master, player1, player2): Frame.__init__(self, master) self.pack(expand = 1, … | |
Re: Or, convert the zip to a list.[CODE]def swap(t): return t[1],t[0] x=zip((1,3,1,3),("param","dorie","kayak","canoe")) w=list(x) print("w=", w) y=sorted(w,key=swap) print('y=',y) z=sorted(w) print('z=',z) l=sorted(w,key=swap) print('l=',l)[/CODE] | |
Re: [QUOTE]if username not in users.usrlist:[/QUOTE]It appears that usrlist contains the user names, so you would want to append any new names to that list. | |
Re: There should be a comma after PIPE (I'm guessing that this is a tuple), and then a communicate statement [CODE]proc2 = subprocess.Popen("/home/samush/Documents/kandidat_arbete/python/cr_to_fr/fortreaderc", shell=True, stdin = subprocess.PIPE,) proc2.communicate('\tstdin: to stdin\n')[/CODE] [url]http://blog.doughellmann.com/2007/07/pymotw-subprocess.html[/url] | |
Re: Try the pygame forum. Most of us are not game programmers [url]http://z7.invisionfree.com/pygame/[/url] | |
Re: [QUOTE] def __init__(self, name): self.__monName = name monFile.write(self.__monName)[/QUOTE]Somehow you are passing a tuple to the class. How do you call the class and what name are you entering? Also, add a print statement before the write print type(self__monName), self.__monName monFile.write(self.__monName) | |
Re: This link is to the while() loop page in one of the many tutorials [url]http://en.wikibooks.org/wiki/Python_Programming/Loops[/url] You have no while loop in your program, so I think you want to start by inserting a loop and experimenting with it. | |
Re: [QUOTE]which prodcues *element,type=s4r,elset=WSLAB 100001,6,4719,6308 ,12 *element,type=s4r,elset=WSLAB 100002,4719,2328,2327 ,6308[/QUOTE]It appears that you have a newline in with the final element of the list, so after the exchange, the next to the last element prints the newline which puts the last element on the next line. You should .strip() before appending to … | |
Re: I use multiprocessing / pyprocessing as follows. Also subprocess has replaced the os.popenX functions [url]http://blog.doughellmann.com/2007/07/pymotw-subprocess.html[/url] [CODE]import subprocess import time from processing import Process class TestClass(): def test_f(self, name): subprocess.call("ping www.google.com", shell=True) if __name__ == '__main__': CT=TestClass() p = Process(target=CT.test_f, args=('P',)) p.start() ## sleep for 5 seconds and terminate time.sleep(5.0) p.terminate()[/CODE] | |
Re: [QUOTE]ImportError: No module named sqlalchemy.exc[/QUOTE] Is the program/file actually named "sqlalchemy.exc". Looks like it's maybe a typo. Also, import usually assumes a ".py" ending. | |
![]() | Re: I think the way to go about this is to use modulo or divmod to find the numbers that you can divide the given number by. That is the remainder == 0. You will be working with single numbers which is less confusing. Actually, you can use the (given number … |
Re: I don't remember if SQLite is installed by default or not. A test is of course import sqlite3 Even though you may not use it, there are various apps that do. Also, check out the programming forum there [url]http://ubuntuforums.org/forumdisplay.php?f=39[/url] | |
Re: [CODE]i_getdata_test = [ \ (30, 0, 0), \ (29, 0, 0), \ (28, 0, 0), \ (27, 0, 0), \ (26, 0, 0), \ (25, 0, 0), \ (24, 0, 6), \ (23, 0, 0), \ (22, 0, 0), \ (21, 0, 0) ] for pixel in i_getdata_test: print pixel … | |
Re: Assuming that sum_results is a dictionary that contains numbers of decimal class, you can use [CODE]total_cost = float(sum_results['list_price']) + salestax + shipping_cost + rush_cost[/CODE]If this doesn't work, then print the type for each variable print type(sum_results['list_price']) etc. You can check the docs for the decimal class at python.org if you … | |
Re: Your existing code looks like it wants to find records where the field "month" equals myprice. The field "sql" is just a string so you format it like any other string. Post back if this isn't enough to get it to work.[CODE] ## assuming month, myprice and mytel are integers … | |
Re: 1. Sort the list and test for this_number == next_number and add one to a counter if a duplicate. 2. Use a dictionary (if you are familiar with dictionaries) with the number as key pointing to a counter. Increment the counter every time that number is found. |
The End.