2,190 Posted Topics
Re: The short answer is to use [URL=http://effbot.org/tkinterbook/wm.htm#wm.Wm.withdraw-method]withdraw or iconify[/URL] but not all methods are available for all widgets. A simple example that creates a normal Tk window, and a second window with a canvas that is withdrawn when you click the "Continue" button, and is raised with the "deconify" button. … | |
Re: You would have to test for "(" and then traverse (or split) to the ")". The letters in between would be divided by 1000. | |
Re: Adding a print statement should help. If you want to store more than one value, a list is usually the container of choice. [CODE]def gp(a1,r,n): ## can also be done with list comprehension print [ a1 * (r ** x) for x in range(n)] while n > 0: n = … | |
Re: You would call it this way (an [URL=http://www.freenetpages.co.uk/hp/alan.gauld/tutclass.htm]intro to classes):[/URL] [CODE]##Test the Lexicon program print'This is a test program for the Lexicon file' # an instance of the class lex_instance = Lexicon() # the class instance now exists so we can call it's members source = lex_instance.OpenFile('word') [/CODE] | |
Re: Works fine for me. Note that you only have to pass minutes allowed and minutes used to the function. [CODE]def calc_total(minutesAllowed, minutesUsed): extra = 0 if minutesUsed <= minutesAllowed: totalDue =74.99 minutesOver = 0 print "You were not over your minutes for the month." else: minutesOver = minutesUsed - minutesAllowed … | |
Re: [QUOTE]The Python program I need to write accepts the price of an item, the amount paid for it[/QUOTE]Start by asking and receiving from the keyboard, the price and the amount paid. Yes, we can help you with code you've written, but won't do it for you. | |
Re: If I can read the 166 lines of code correctly, what happens when "resting" == 1 [CODE] info_dict["resting"] = info_dict["resting"] - 1 ## it now equals zero, so the following would never execute def slime_move_ready(): ## also add a print statement to see if this is executing print 'info_dict["resting"]', info_dict["resting"] … | |
Re: [QUOTE][b,b,a,a,a,a,a,b,b,b,b,a,a,a,a,a,b,b,b,b,a,a,a,a,a,b,b][/QUOTE]You insert 2, then 4, then 4, then 2? Please correct this example or be more specific about what you want. Instead of inserting, it is more efficient to create a new list since every item past the insertion point has to be moved for every insert. You can use … | |
Re: Python uses pointers, which means that D=C assigns the memory address of "C" to "D" so they both point to the same block of memory. | |
Re: [CODE]# the last letter is b,d,g,l,m,n,p,r,s or t if word[wordlength] in ['b','d','g','l','m','n','p','r','s','t']: #and the second to last letter is not the same as the last letter. if word[wordlength] != word[wordlength-1]: # # or (same thing as nested if() statements) if (word[wordlength] in ['b','d','g','l','m','n','p','r','s','t']) and \ (word[wordlength] != word[wordlength-1]): # # … | |
Re: I would keep everything between the first ">" and "<" but if all of the records are the same, you could also replace "<TimeStamp>" and "</TimeStamp>" with nothing. Either way will get you to be able to print(datetime.datetime.fromtimestamp(int("1284101485")).strftime('%Y-%m-%d %H:%M:%S')) | |
Re: "\n" is the newline character, so you are appending a newline every time you write "answer", so remove it there and add a statement to b.write "\n" every time a comma is found (and it is not apparent from the code posted how you test for a comma). Note that … | |
Re: For the unknowing, this is another example of the "never-ending-questions-with-little-or-no-code" method to get other people to write the code for them. The method is to keep asking questions until someone is worn down enough to write the code for them, while they sit on the veranda in the shade. Let … | |
Re: It sounds like you would have to alter the perl script to accept input/inputs from some source other than the command line. You could use multiprocessing to run in parallel, or use one of the parallel python programs, especially if you have multiple cores [url]http://github.com/mattharrison/coreit[/url] [url]http://www.parallelpython.com/content/view/17/31/[/url] | |
Re: [QUOTE]faces=rect64(acb64583d1eb84cb),2623af3d8cb8e040;rect64(58bf441388df9592),d85d127e5c45cdc2[/QUOTE]It appears that you could split on the comma and then on the semi-colon since you want the last string in the pair. Then flatten the resulting list. Otherwise, parse each line and look for a start and stop copying character (which may be easier to understand and is a … | |
Re: It should be easier if you use a dictionary pointing to a list of shares. This code assumes that you do not care about order of execution, otherwise you will have to order the dictionary keys and execute in that order. [CODE]def get_config(): ip_dict = {} done = False deny … | |
Re: Print what you have first because it doesn't look like it is doing what you would want if "number_list" is a string and has not been split into words. [CODE]def turn_words_into_numbers(number_list): output = 0 current = 0 for index in range(len(number_list)): current = eval(number_list[index]) print index, number_list[index] [/CODE] Some theory: … | |
Re: random.sample() returns a list (of cards in your case). [CODE]import random x = ["a", "b", "c", "d", "e"] ret = random.sample(x, 2) print ret, type(ret) [/CODE] | |
Re: This line db[j][0]=db[j][1] overlays the English word in the list with the Spanish word. And do not use "sum" as it is already taken by Python for summing numbers, and "i", "l" or "O" are not good choices for single digit variable names as they can look like numbers. [CODE]db … | |
Re: Find where the error is. Print line2[j], j, len(line2) and with a separate print statement a[j], j, len(a). You can then fix the specific problem. Also, include some comments in the code explaining what is happening, so we know what it is supposed to be doing. No one can be … | |
Re: [QUOTE]takes a list of real numbers as input[/QUOTE]And how are the numbers input; from a file, or via the keyboard. Whichever it is, that is where you want to start. Read the input from a file or the keyboard into a list, and post that code for further help. | |
Re: Some modifications to your code 1. Used a list for keywords instead of if() statements 2. Added an indicator that turns on when "description" is found and prints those records. Add whatever to want to process those records instead of the print statement under "if des". [CODE]infile = open("books.txt","r") lines … | |
Re: It would be something like from cart import items if cart.py is the name of the file. But without knowing what type of object cart and items are, there is no real way to answer the question. Post a simplified example. | |
Re: What GUI toolkit are you using and what type of object is "frame"? | |
Re: Since there is no code on how or how many items in self.play_hands were declared, and no error message or what happened versus what was expected to happen, there is no way to comment. Generally, you would use list comprehension. [CODE]self.player_hands=[["Testcard"] for x in range(self.num_of_players)] [/CODE]Also, "i" l" and "O" … | |
Re: The limits of floating point numbers [url]http://www.lahey.com/float.htm[/url] [url]http://docs.python.org/tutorial/floatingpoint.html[/url] Use decimal for more precision. [CODE]from decimal import Decimal as dec # 0.1 + 0.1 + 0.1 - 0.3 = 0.0 x = dec("0.1") y = dec("0.3") print x + x + x - y [/CODE] | |
Re: When the if() statement is not executed, there is no "x" to return. Note also that the statement "return y" will never be reached/executed. | |
Re: Start with the smallest divisor, 2; see if it is a divisor and increase up to the square root + 1. So in this case 252 / 2 = 126 So 2 is a divisor. Then using 126 (divide by 2 up to square root 126 + 1) 126 / … | |
Re: Who wants to know this, why do they want to know, and what's their secret motive for collecting all of this information? By definition, no one who takes the test could be a conspiracy theorist. | |
Re: See "Playing & creating sound" [URL=http://wiki.python.org/moin/PythonInMusic]here[/URL]. I have on use Snack so can't really comment on any of them. | |
Re: See [URL=http://www.daniweb.com/forums/thread325522.html]this post[/URL]. If you're not in the same class and have a different problem, post back with the differences. | |
Re: [QUOTE]Use the Date, Volume, and Adj Close fields to calculate the average monthly prices. Here is a formula for the average price for a month, where Vi is the volume and Ci is the day i’s adjusted close price (Adj Close). averagePrice = (V 1 ∗ C 1 + V … | |
Re: Post the code as it is now. Note that you should now be using a tuple, so code has to be changed, like this example: [CODE]# pick one randomly from the sequence word_tuple = random.choice(words_and_hints) # create a variable to use later to see if the guess is correct word … | |
Re: The brute force way to guess would be to generate a list of 50, or 1000, numbers, and delete the guess from the list. Then use random.choice(numbers_list) to generate the next number. You would also want to slice off part of the list when you change the lower or upper … | |
Re: Convert to [URL=http://effbot.org/librarybook/datetime.htm]datetime.date[/URL] and you can then compare for greater or lesser than. | |
Re: Some print statements should help. Note that "word" will only contain the final word in a sentence. Once you can get each word, add a counter to count the letters as they are added to the new "word" field or what ever you wish to use. [CODE]m = input("Enter a … | |
Re: The answer is simple. Put Some Damn Locks On The Lockers! You have to have a way to keep track of the lockers that you understand. It can be as simple as a list of integers that you set to zero/false for closed, and 1/true for open, that is sent … | |
Re: First suggestion is do not post 145 lines of untested code and expect your forum servants to wade through all of it. Second, your if/else indentation is screwy, and there is a while() loop in the middle, which may or may not be at the correct indentation level. Third, you … | |
Re: Since "lst" is used on 5 lines of the code, there is no way to tell where the error is. General comments would be the list "prime" is an exact copy of "lst" and so you return a copy of the initial "lst" list. Also, print len(lst) before this statement … | |
Re: [QUOTE]I want it to simply give me the logged-in users password.[/QUOTE]Generally speaking, programs do not know passwords. A programs takes the password the user entered, converts it using some encryption algorithm, and compares to the stored password (stored in encrypted form only). Otherwise, anyone could steal any password with a … | |
Re: [QUOTE]trying to do it with a while loop[/QUOTE]Post your code so we have something to comment on. Also, using a dictionary or list is separate from the for() or while() loop. | |
Re: Rolling your own is the best way to go. Alternatively you could replace "?" and "!" with "." and split on the period, but that requires many loops through the file. | |
Re: What happens if the first "Steve" is 7 instead of 1 -----> ['steve',7, 40], ['steve',3, 20], ['steve',2, 30]], etc. Should it be at the end of the first list or at the end of all of the items? Generally, you would flatten the list and then sort if all items … | |
Re: [QUOTE]I must fix a code so I can write roman letters (bigger than 3999)[/QUOTE]For Arabic, if it is larger than 3999 subtract 1000 and add 1000 to a separate field until it is less than 4000. You would then divide the "thousands" field by 1000, convert and print with parentheses, … | |
Re: Vegaseat did one a while ago and posted it [URL]http://www.daniweb.com/forums/thread198855.html[/URL] I think most GUI toolkits include methods to do this. [CODE] import Tkinter as tk root = tk.Tk() def show_pw(): pw = pw_entry.get() label2['text'] = pw label1 = tk.Label(root, text="Enter password for user Frank: ") # shows only * when … | |
Re: You are going to have to store the widgets in a list or dictionary to do that, and tell remove() which one you want to delete. The following is a program that shows how to associate a button to a specific dictionary member by binding a unique instance of the … | |
Re: I get an error because .txt was not in quotes. Also note that you will get an aditional error because "options" is declared after the --output parser statement. | |
Re: There is at least one other post on this site that already does this. A search should bring it up. | |
Re: [CODE] #repeat print 'Enter type (string)' type = str(raw_input()) [/CODE]"type" is reserved by Python as a function name that returns the type of an object; a string, class, integer, etc. Use "category" or some other name that is less confusing. Also, raw_input returns a string so type casting to string … | |
Re: Do you want to take each record and print it as a column under the heading? |
The End.