2,190 Posted Topics
Re: Add "Solved" or "Ignore This" to the thread title and in a day or two it will be too far down the list to notice. | |
Re: Use the datetime module. Note that using the separate variable, start_time, is not necessary. start_time = datetime.datetime(2008, 06, 03, 12, 30, 00) diff_time = datetime.datetime(2008, 06, 03, 12, 50, 00) - start_time print diff_time.seconds, type(diff_time) print "duration in minutes =", diff_time.seconds/60 [url]http://effbot.org/librarybook/datetime.htm[/url] [url]http://blog.doughellmann.com/2008/03/pymotw-datetime.html[/url] | |
Re: Start with defining the public and private members. You should also read your own post. There is duplication re defining the class named "Corvette". Rework it so that things are clear and only defined once. | |
Re: "Bold" is a function of the program displaying the text. In postscript it is /Helvetica-Bold findfont % Get the basic font 11 scalefont % Scale the font setfont % Make it the current font You can use this if you are printing the file to a printer. For a word … | |
Re: [QUOTE]an someone show me some code to convert rankine temperature to kelvin? rankine is in the same scale as fahrenheit, but it starts at absolute zero. so 0R = -459.67F, heres is what I have[/QUOTE]So rankine would be fahrenheit -459.67 the way I read what you have said[CODE]def to_rankine_from_celsius( tempC … | |
Re: [QUOTE]I have a .dbf file which contains three fields: an id (1), a Mapsheet # (455626) and finally a Mapsheet Name that corresponds to the Mapsheet# ( Big Lake ).[/QUOTE]I assume you are using something like dbfpy to read the file, so populating the dictionary would be fairly simple. The … | |
Re: This will traverse all of the subdirectories and do what I think you want it to do. I have added some print statements which is probably enough by itself to answer your question as is shows what the root, dirs, and files contain. If you want to limit it to … | |
Re: [QUOTE]create a counter that counts how many weeks a certain value gets exceeded[/QUOTE]I would suggest using a function for simplicity. Return a "True" or one if the value is exceeded. This also only returns one positive. If it is possible that the value is exceeded more than once in a … | |
Re: One advantage of the class structure is that you don't use globals but self.var_name.[CODE]import random class Cards(object): def __init__(self): self.cards = {2:4,3:4,4:4,5:4,6:4,7:4,8:4,9:4,10:16,'ace':4} self.player = [] self.playert = 0 self.comp_tot=0 self.comp = [] print self.playert,'hi' print "The Game is Blackjack" def draw(self): f = self.cards.keys() a = random.choice(self.cards.keys()) self.cards[a]-=1 if self.cards[a] … | |
Re: Not nearly enough info. You'll have to include the code (using code tags because whitespace counts in python-see the "Please use BB Code and Inlinecode tags" thread) and a complete error message For starters, your code should read[CODE]def X(a,b): c = a+b ## note that the backslash is not necessary … | |
![]() | Re: You can also use the var.find("-s") method for strings and then slice it. It depends on if -s"password" is the only thing in that record or not. ![]() |
Re: We had a topic like this a short while ago. The easiest/most efficient method is to use two sets and compare with set1.difference(set_2) and vice-versa. Also, python has difflib which may or may not be more than you want. [url]http://docs.python.org/lib/differ-examples.html[/url] | |
Re: Since you enter the Python interpreter, run the program, and then exit the interpreter, I don't think there is a way. The interpreter will always return you to the original directory when it exits. Perhaps someone else will have other ideas on this. | |
Re: Add some print statements to see what is going on and it should become obvious. [CODE]for ID1, begin1, end1 in file_1: print "file_1 =", ID1, begin1, end1 for ID2, begin2, end2 in file_2: print " file_2 =", ID2, begin2, end2[/CODE] | |
Re: A link to a Tkinter tutorial/reference [url]http://infohost.nmt.edu/tcc/help/pubs/tkinter/[/url] | |
Re: Also, this will not work. You have two separate blocks of memory. I have reduced your code so it only tests the year variable. The value at memory block #2 never changes so that snippet only prints once, (i.e it is initialized as year[memory block #1]+1 = 0+1 at a … ![]() | |
Re: OpenOffice will import comma delimited text files, or any other delimiter that you care to choose. If there are commas in the data then use something like comma+space+space as the delimiter. Here is a dated link for creating the spreadsheet in python. It refers to StarOffice (or something like that), … ![]() | |
Re: "list index out of range" has nothing to do with the size of the list AFAIK. If the list were too large there would be some sort of out of memory message.[QUOTE]Is there any other efficient datastructure other than lists and dictionary to serve the purpose ?[/QUOTE]SQLite can be used … ![]() | |
Re: It might be helpful to take a look at the "Starting Python" at the top of this forum. There are 5 pages, so don't have to wade through 100's of pages to get you started. | |
Re: Obviously this is not a list of numbers, so you want to take a look at the function that returns this. Add print statements to see what is going on throughout the program until you understand what is happening | |
Re: If you want to run this program file by itself, put the following at the bottom. You can then run the program from the command line with "python program_name". Take a look at the "Starting Python" thread at the top of this forum. [CODE]if __name__ == "__main__": opener[/CODE] | |
Re: You best bet would be to ask the person on python-forum.org who wrote this program. They would understand it better than anyone else. No one wants to spend their time answering a question that has already been answered on another forum. | |
Re: You may have more than one block of memory named "LawRecite". If you assign True in a loop or function then it is local to that loop/function and will be destroyed when you exit unless you return the value from the function. Change any variable names that are in a … | |
Re: [QUOTE]The problem is I need to take the names of the images in Directory A and apply them to the images in Directory B.[/QUOTE]What does this mean? Rename a file with some unknown name combination? See if a name in is both dirs? | |
Re: There has to be better code to copy. Unless you have to modify that specific program, I would suggest finding program without the Tkinter stuff and copy that. You can add a GUI later after the rest of it is working. Also, when you copy a program and are trying … | |
Re: And apparently a variable as well readLines = readLines(line,lines,lineNumber) isPageValid = isPageValid(testLine,validPages) Try this instead[CODE]def isPageValid(testLine, validPages_list): ##isPageValid = False <----- Not Used for valid_page in validPages_list: if testLine in valid_page: ## or do you want ## if valid_page in testLine ? return True return False[/CODE] | |
Re: If you are not changing the contents of one or both of the lists, then use a tuple instead:[CODE]tuple1 = tuple(list2)[/CODE] | |
Re: To copy a list you would use a3 = a[:] print a3 If you don't want an exact copy you would append to another list[CODE]a=['city','village','town','capital'] a3=[] for x in a: print "x in a =", x if x.startswith( "c" ): print " appending", x, "to a3" a3.append(x) print a3[/CODE] | |
Re: Deleting new_num from x does nothing useful. You are using num and deleting new_num which may or may not be in x. You want to append to y if num > 0[CODE]for num in x: if num > 0: ## eliminate if num-1 <= zero y.append(num-1) b+=1[/CODE] | |
Re: New entries are not being over-written. You are initializing to an empty dictionary with the statement results[p] = {}. Perhaps (and just perhaps) a dictionary of classes would serve better. Note that SQLite can also be used in memory, i.e you can store and lookup '2.0' + 'Conditions' + 'Vane2INLET', … | |
Re: It's something along the lines of os.system("firefox http://www.google.com") | |
Re: Did the shelve module work or do you still want to debug the dictionary class? | |
Re: Some modifications to your code. First you have to test for zero, and second, the variable "b" is not necessary as you can just use len(x). Hopefully this is what you want to do. [CODE]def kopi(x): y = [] for num in x: new_num = num - 1 if new_num … | |
Re: I'm not sure comparing words will give the best results. If two articles use "and", "the", "a", "of", "to", etc. a lot then they will be deemed similar. If you want to do it that way, then go through each of the two files and place unique words in a … | |
Re: And if you mean something very simple to time some program once, use datetime. [CODE]import datetime import time start_time = datetime.datetime.now() time.sleep(2) print datetime.datetime.now() - start_time[/CODE] | |
Re: See the second entry here at effbot [url]http://www.google.com/search?ie=UTF-8&oe=UTF-8&q=python+from+import[/url] | |
Re: Use code tags and submit some sample data in raw form and how you want it to appear after formatting. There is not enough information in your post. ![]() | |
Re: You will have to identify the global variables, bet et al. Otherwise, you will be using a second block of memory that is also named bet but local to the function.[CODE] if bet == "quit": break elif float(bet) <= 0 or float(bet) > x: print "Invalid bet." else: print x, … | |
Re: See 7.2 at this link, "Reading and Writing Files". [url]http://docs.python.org/tut/tut.html[/url] | |
Re: Add a print statement at the beginning of who wins to see if you actually enter it or not. If the value of turnTuple is not found, nothing will happen. And this definitely should be a class IMHO. It's time to learn classes. It will make coding a lot easier.[CODE]def … | |
Re: Insert some print statements to see what is happening. You may have a LF, "\n", at the end of each aPol_data item in which case you will see an extra empty line when printing old, so it doesn't match any word without one. If this is true, you will have … | |
Re: The Python Imaging Library has tiff routines. Before beating your head against the wall, see if you can use it. If not, post back with an example or two of what you want to put into the metadata. Image formats have become very optionated. | |
Re: If this is a line of data from the file 28.618382 27.631520 44, followed by 28.618382 27.631520 22 etc, then you can use split() instead of checking for tabs. Also, you can pass a string as a parameter to file open() [CODE]## simulate a file read data = [ "28.618382 … | |
Re: 1) You don't return x from the function so it is not visible outside the function. 2) You have multiple variables named "i" (Please don't use, i, l, or o as they look like numbers and there as 23 other letters that work just as well) for i in range … | |
Re: If you want both verb and prep to be found in count created by the existing code [CODE]from collections import defaultdict total_found_dic = defaultdict(int) if (verb in count) and (prep in count): total_found_dic[(verb, prep)] += 1[/CODE] Note that you want to test sub-words and print the results to see what … | |
Re: Have you tried sys.stdout.flush()? I don't know if that will work or not. Also, you want to begin to move over to the subprocess module. Theoretically, it should flush the buffer whenever you issue a read stdout using subprocess. I guess no one else has much to offer on this. … | |
Re: A) Stop feeding it your brains B) Hint, it's a __carpet__ python. BTW watt is spelled "watt", not wat, and python's don't eat watts, lightbulbs do. | |
Re: Are you on a Mac or Linux? Libfmodex if available for both. It appears that you don't have it installed although it could be installed someplace that is not in the path. Try searching/installing fmodex or libfmodex. | |
Re: I think Blade321 also wants to ask for input if the numbers don't agree and assign it to the variable x (instead of printing it)[CODE]x=0 y= 1234 n=0 while x <> y: x = int(raw_input("Enter a number " )) n += 1 if n > 10: break[/CODE] | |
Re: Append everything to c[CODE]a = [ "is", "cool"] b = ["Peter", "James", "John"] c = [] for name in b: c.append( [name, a] ) print c [['Peter', ['is', 'cool']], ['James', ['is', 'cool']], ['John', ['is', 'cool']]][/CODE] |
The End.