2,190 Posted Topics
Re: See geometry strings [URL=http://infohost.nmt.edu/tcc/help/pubs/tkinter/std-attrs.html#geometry]here.[/URL] "Geometry" sets the size and location of a widget. | |
Re: You should sort both words and compare. Your code will compare "a" to "aa" and find them equal. Note that any anagram program will take "odg" and return "god" and "dog" which is all it can do. [CODE]infile = open ("/usr/share/dict/american-english", "r") ## "dict" is a reserved word words_in = … | |
Re: Consider posting this in the tutorials forum also so we can find it later [url]http://www.daniweb.com/tutorials/forum114.html[/url] | |
Re: move() should probably receive a distance parameter. You might use something like this, although it is not obvious from the question what the fuel and distance moved relationship is. [CODE] def move(self, distance): ## do you want to use floats or integers here? fuel_used = distance / miles_per_gallon if self.fuel-fuel_used … | |
Re: You possibly want to use a Frame widget. One of the online references is [URL=http://effbot.org/tkinterbook/tkinter-index.htm#class-reference]here.[/URL] | |
Re: There is no real difference: [CODE]if condition == True: if condition == "True": [/CODE] | |
Re: What exactly are you looking for and what exactly to do want to replace it with? You can also use string.find which will return the starting position or -1. If you want to remove "The POST" and "is vulnerable" then replace() is the simplest way to go. | |
Re: How to start programming is not within the scope of most forums. Start with a tutorial [url]http://www.pasteur.fr/formation/infobio/python/ch11s02.html[/url] [url]http://www.freenetpages.co.uk/hp/alan.gauld/tutloops.htm[/url] [url]http://wiki.python.org/moin/BeginnersGuide/NonProgrammers[/url] We can and will help with code that is formated properly but does not function as expected. | |
Re: [quote]I get a result of an integer 1 - 5, say 3 - I would then like the script to tell me what string is assigned to it, in this case 'a'...[/quote]Except that no one realized that the dictionary is bass-ackwards. [CODE]ltr_dic = {1: 'a', 2:'a', 3:'a', 4:'b', 5:'c'} # … | |
Re: You can use a tuple of the first 3 columns as a dictionary index. [CODE]f_list=open(sys.argv[1]).readlines() ## you can use a set or dictionary unique_dic = {} for rec in f_list: sub_str = rec.split() key = (sub_str[0], sub_str[1], sub_str[2]) if key not in unique_dic: unique_dic[key] = 1 for rec in open(sys.argv[2]): … | |
Re: Add some printing to figure out what you are testing. Link to [URL=http://diveintopython.org/file_handling/for_loops.html]iterating through lists[/URL]. [CODE]def e_words(m): forbid = 'e' word = m.split() print "testing", forbid, "in", word if forbid in word: return forbidword [/CODE] | |
Re: I think the problem may be that you are not entering "N" for the "do you want to go first" question as you have an infinite while loop, and not one the doesn't repeat. The main problem with this code is that you have 54 lines of code that have … | |
Re: Post some trial code for as much of "A. put all words in lower case and omit all punctuation" as you can so we have something to comment on. "put all words in lower case" = use the lower() function "omit all punctuation" = loop through the text and omit … | |
Re: Take a look at [URL=http://www.daniweb.com/forums/thread173615.html]this previous post[/URL] | |
Re: [QUOTE]It will Only proceed to execute background.start() when I press "Control + C" to terminate, and it then spews out the ls and then the final print statement.[/QUOTE]Can you run the thread from GTK, say when someone presses a button? Obviously GTK's locks prevent what you are doing. Running it … | |
Re: [QUOTE]i dont know how to make it produce 2d movements[/QUOTE] If you have an graph with an x and y axis, you can advance in a postive or negative direction for either axis. To keep it simple, point 1=(3,1) for x and y, point 2=(-3, 2) for x and y, … | |
Re: I use os.kill(), but some of these are OS dependent and Python version dependent. Take a look at [URL=http://www.doughellmann.com/PyMOTW/subprocess/index.html#module-subprocess]Doug Hellmann's examples[/URL] for starters. | |
Re: Code this one step at a time. So first, get the input and check that it is indeed 'r', 'p', or 's'. Then generate a random choice for the computer, etc. BTW you have a lot of redundant code in this function. [CODE]def play_RPS(x, num_games): print 'Press q at any … | |
Re: You are continually drawing one oval on top of another, so Tkinter has to keep track of more and more widgets, not to mention that you could reach the recursion limit. Change the color instead. This code is a little crude, but I don't have any time right now. [CODE]import … | |
Re: [QUOTE]but it is obvious I'm too dum to learn [/QUOTE]or to use a spell-checker. Converting from one data type to another is called [URL=http://www.pasteur.fr/recherche/unites/sis/formation/python/ch02s07.html]"type casting"[/URL], so to an integer would use int(). [CODE] str_list = ["1", "3", "5"] for x in str_list: print x, type(x) print int_list = [int(x) for … | |
Re: [CODE]for lines in textf: if ask in textf:[/CODE]Print "textf" before the "if" statement so you know what you are testing. Using logic like this, entering a word like "the" will find "the", "then, "either", etc. You might want to split the file input into words and check for equal condition … | |
Re: This is left bit shift [CODE]while Step << 32: # while Step < 32: ## instead? [/CODE]If you want to increase the speed of a motor, at higher motor speeds the same increase will yield a greater increase in the speed of the motor because of the initial friction which … | |
Re: 1) Choose a title that will get people to read the question 2) Sort the list and replace the first 5 numbers with the last 5 | |
Re: The easiest way is to use Python's count() function (and then test for a result > 0) for smaller groups of numbers. Some info on [URL=http://effbot.org/zone/python-list.htm]using lists[/URL]. A list can also be used by element or index number. Element[0] = the number of zeros found, element[1] = number of ones, … | |
Re: Excuse me for butting in, but this is poor style. Try instead: [CODE] for word in words: if word not in d: d[word] = word [/CODE] | |
Re: Yes, both can be done. You would use a for() loop to traverse the strings, or convert to a list, in both cases. | |
Re: [quote]Id like it to look like this Multiply ,x times ,y[/QUOTE]See [URL=http://docs.python.org/release/2.5.2/lib/typesseq-strings.html]string formatting[/URL]. [CODE]print "Multiply", x, "times", y print "Multiply %d times %d" % (x, y) [/CODE] | |
Re: Generally, an IDE has a "convert tabs to spaces" option which takes care of this, and I show tabs in lines 11 and 12. | |
Re: [QUOTE]whenever i add in line "n = fin.readline()", i get an Mixed Iteration variable error:[/QUOTE]for line in fin: and n = fin.readline() do the same thing. Choose one or the other. You can also do a for line in open("constitu.txt"): (is the same thing) as well. Also, a hint below. … | |
Re: [QUOTE] How to add an entry to the file /etc/apt/sources.list[/QUOTE]sources.list is a list of the repositories to search. It has nothing to do with the individual packages. Try 'man dpkg' and you should find something similar to (I don't remember the exact syntax for dpkg) dpkg -f package_name which you … | |
Re: The problem here is not getting records from the file. The problem is that you have large blocks of untested code. I am adding one print statement and a list declaration as a hint: [CODE] def read_from_file(self,room_table): if room_table is not None: fp = open(room_table, 'r') file_list = fp.readlines() fp.close() … | |
Re: Try this first: [CODE]def main(): fileInput = 'PlayerNames.txt' wordList=[] print exportTextList(fileInput, wordList) ## <----- [/CODE]and then see the "gc_counter" function [URL=http://www.pasteur.fr/formation/infobio/python/ch01.html#d0e115]here.[/URL] | |
Re: [QUOTE]_tkinter.TclError: couldn't open "horse.gif": no such file or directory[/QUOTE]It could not open the file. Try it with the complete path. | |
Re: See [URL=http://www.daniweb.com/forums/thread320708.html]this link[/URL]. The same question (summing items) was asked 2 days ago. | |
Re: I like using deque's appendleft for coding reverse sequence. You would of course use loops for row and column and eliminate the redundant statements here: [CODE]from collections import deque ctr = 12 print_list = deque() print_list.append(ctr) ctr -= 1 print_list.append(ctr) ctr -= 1 print_list.append(ctr) ctr -= 1 print print_list print_list … | |
Re: You don't return or receive anything for numbers not equal to zero. The function calls itself many times. Each function call must receive the return value when the function it calls finishes, and then return that value to the function it was called by. [CODE]def recursion_test(value): """ recursion example incrementing … | |
Re: Or use something like easyGUI or Tkinter. [CODE]import easygui """ test of multi-enter box """ def multeasygui_date() : title = "Date" msg = "Enter Date" fieldNames = ["mm","dd","ccyy"] fieldValues = [] # we start with blanks for the values fieldValues = easygui.multenterbox(msg,title, fieldNames, fieldValues ) #---------------------------------------------------------------- # from here down … | |
Re: [QUOTE]File "<stdin>", line 11 t1.append(list[temp]) [/QUOTE] "list" is a function so it should be t1.append(list(temp)) In the future, if there is an error for a compound statement, break the statement into it's individual parts to see which part is causing the error. | |
Re: See [URL=http://www.daniweb.com/forums/thread320234.html]this link[/URL] for the same question. | |
Re: Assuming k is an integer, it will never be less than "n" because "n" is a string, as already stated. Print both "k" and "n" to test.[CODE]def otsi(k): if (k < n): print "k < ", k, n # # instead of recursion you should be using a while loop … | |
Re: Double check your average calculations, as generally you can not add averages together. See [URL=http://www.greenteapress.com/thinkpython/html/book006.html#toc53]"Conditionals" here.[/URL] [CODE]if average > 90: grade = "A" Etc [/CODE] | |
Re: A place to start, without coding the solution for you. Post your code for help with further problems. [CODE]main_list = [['a', 'b', 'c', 'd'], ['e', 'f'], ['g', 'h']] for each_list in main_list: print "\n New List" for ctr in range(len(each_list)): print ctr, each_list[ctr] [/CODE] | |
Re: I don't use MySQL, but try using this line instead and see what happens. [CODE]abc = "SELECT * FROM Details" records = cursor.fetchall() [/CODE] and is the table named "Details" or "mydb". | |
| |
Re: What happens if you have more than one key with the same maximum? Instead of print, store the key and item if it is greater than the maximum so far. | |
Re: You can use split() if I understand correctly. [CODE]locTextFormat = "COUNTY --- TOWN" print locTextFormat.split("---") ## ## or is it COUNTY = "test_county" TOWN = "test_town" print COUNTY + " --- " + TOWN print "%s --- %s" % (COUNTY, TOWN) [/CODE] | |
Re: [QUOTE]I am still getting a systex error when closing the file[/QUOTE]We can't really guess what that is. Post the entire error message. As a general rule, check that line of code and the previous for the same number of open and closing parens. If there is a paren error on … | |
Re: Put the above code in a [URL=http://www.greenteapress.com/thinkpython/html/book004.html#toc28]function[/URL] and then call the function from a loop. You can use one function to get the width or the length as well by passing the maximum allowed value and the literal to print, "Width" or "Length", to the function. Note that the [URL=http://www.python.org/dev/peps/pep-0008/]Python … | |
Re: Lists work better IMHO because you can alter each element (letter) individually. This is an example of how you could code a solution using lists. Hopefully some print statements will be enough to append the hyphenated string portion of your code. If not post back with questions. There are some … |
The End.