2,190 Posted Topics
Re: Looks like you are only asking 2 questions. [CODE]=====> if (correct + incorrect) < 2: <===== self.button = Button(win, text = 'Next Question') self.button.config(command = self.action) self.button.pack() if self.action == None: incorrect += 1 else: correct += 1 else: self.label.config(text = 'Number correct %i' %correct) [/CODE]And, you might consider a … | |
![]() | Re: [QUOTE=ChargrO;1211031]sorry wrong error this is the error AttributeError: Application instance has no attribute 'toggle'[/QUOTE] "toggle" is no longer a member of Tkinter. You re-defined it as a member of your Application class. |
Re: You have to define "different" before you begin. Do you want to compare the first record in the first file to the first record in the second file, and the second record to second record, etc.? What happens if one of the files has one record more than the other … | |
Re: [QUOTE] I've tried everything and it gives me all types of errors.[/QUOTE]It worked find for me. I clicked button 8 and it displayed "button 8 clicked", so you'll have to include the error message(s) for any further help. | |
Re: I generally use a dictionary to store the buttons, but in any case you pass the button number to a callback bound to the specific button. You should also use one function to create a button, and pass the button's text, etc. to the function. Note that this does not … | |
Re: You should not be using "string" as a variable name as it is used by Python. Also, "i", "l" and "o" are not good choices for single letter variable names as they can look like numbers. [B]Test each function individuallty[/B] and see comments in the code. [CODE]def searchAuthor(dataList, string): print"\n" … | |
Re: [QUOTE]The idea is for the python - tk-inter window to pop up just after boot up and start its routine.[/QUOTE]There is no GUI until X is started so no Tkinter (you may be able to use TCL or Curses depending on when you run it), so you should add the … | |
Re: Add some print statements to ferret out what's happening, for example: And Idle (comes with Python) is much easier to use than the Python shell/command line. [CODE]word=str(raw_input("Please enter a string:")) ## Don't use 'string' as a variable name input_string ="word" word_rev =word[::-1] print "comparing", input_string, word if (input_string == word_rev): … | |
Re: [QUOTE]My question is - should all strings be Python strings[/QUOTE]It's always a good idea to convert to Python strings. | |
Re: What method are you using to access the office computer from home and can you sign in and get the necessary permissions so as to execute files from home? [QUOTE]2. Check if the latest nightly build has been successful. If it is successful, deploy it on a test environment by … | |
Re: The "standard" way does not use regular expressions. When "<test>" is found, start appending records to a list. When "</test> " is found, print or do whatever with list and re-define it as an empty list, and continue down the line. | |
Re: Using canvas.delete() speeds things up considerably. I have added timing to the DrawBall() function. It starts around 0.000060 seconds and takes double the amount of time after a few seconds. I would guess that this is because of the use of global variables (globals take more time than locals), but … | |
Re: You are on the right track with the dictionary, but am not sure exactly what you want to do. Some input and output data might help. This code is an example of what I think you want. [CODE]SYMTAB = {"START":' ', "BYTE":" ","WORD":" ", "RESB":" ","RESW":" ","END":" ","BASE":" ","NOBASE":" "} … | |
Re: I tested your code for n=100,000 and "while(sun!=n and i<100000)" instead of i < 10**30 (you aren't going to do anything in 4 seconds using 10**30). It took 11 seconds for the prime function and one second for the remainder, so < 10 million would take 100 times as long … | |
Re: [QUOTE]What i am trying to do is take the list of strings, which must be of equal length, and use a nested for loop to go over each character and its neighbours for creation of the relevant equations.[/QUOTE]This solution is similar to a tic-tac-toe game, except the board can be … | |
Re: Yo write what you want to keep to a separate file. Start here [url]http://www.greenteapress.com/thinkpython/html/book015.html#toc154[/url] | |
![]() | Re: This is a tricky one (note the parens in the statement). [CODE]L = [ [4,5,6] , [2,4,5] ] new_L = [ (y if ctr > 1 else y*y) for x in L for ctr, y in enumerate(x)] print new_L [/CODE] |
Re: You will have to include the complete error message, which prints the line where the error was found. We are volunteers so no one will take the time to try and guess which line is causing the error. [CODE]A complete error message looks like this: ./test_1.py File "./test_1.py", line 20 … | |
Re: You could probably use subprocess' readline & write. Doug Hellmann has an example here [url]http://blog.doughellmann.com/2007/07/pymotw-subprocess.html[/url] | |
Re: Try self.Destroy() The wiki has examples [url]http://wiki.wxpython.org/Getting_Started[/url] | |
Re: To find a sub-string within a string, find a sub_string within a string. [CODE]st = "VTK/Examples/Test" to_find = "VTK/Examples/" start = st.find(to_find) if start > -1: print st[start+len(to_find):] [/CODE] | |
Re: [QUOTE]You can change completely the effect of your program by modifying only the last line. This is very useful when you're extending, debugging or testing your code. You cannot do this with code at script level.[/QUOTE]If you want to use this style of programming then you should use function names … | |
Re: A Google of "Perl to Python" will yield some of the programs that will do this for you. If the translation is incomplete, post the offending code, [B]with an explanation of what it should do[/B], and someone will help. Note that this code appears to call other functions, so just … | |
Re: [QUOTE] I need to change presArray = Table1Builder(60, "STR") to presArray = Table1Builder(60,3, "STR")[/QUOTE] You would first have to change the Table1Builder code so it would accept another arg. No offense, but if you are asking this question then you do not want to start changing code. So you have … | |
Re: [QUOTE]I want to generate seprate log files for every sql files in loop.[/QUOTE]You would open a unique file within the loop, before you start reading the SQL file, and close the file after the last record is copied. That's pretty basic so perhaps I am missing something. | |
Re: [QUOTE]Wait, I see a money making opportunity here. I'll apply for a government grant to study how often people publicly announce that they just took a dump [/QUOTE]This could also affect water pressure levels so count me in as a co-conspirator, er co-researcher. In Los Angeles several major water pipes … | |
Re: Using datetime's timedelta, you would use year, month, and day. See "date objects" here [url]http://docs.python.org/library/datetime.html[/url] [CODE]tomorrow = datetime.datetime.now() + datetime.timedelta(days=1) print tomorrow.day ## etc [/CODE] | |
![]() | Re: See the Student class under "Key Functions" here [url]http://wiki.python.org/moin/HowTo/Sorting[/url] if you are talking about a list of classes. Also, see the "The Old Way Using the cmp Parameter" on the same page. ![]() |
Re: [QUOTE]but i just cant seem to get it right[/QUOTE]Show us what you have tried and we will help make it work. It appears that you copied some simple rock-paper-scissors, and guess-the-number code from somewhere and now want us to modify it for you. | |
Re: It appears that you did not test this code as you only read the first rec. Also you can use for rec in inFile instead of the while loop. And string.split() is deprecated, use line.split() instead. [CODE] line = inFile.readline() ##--------------------------------------------------------------- ## this is an infinite loop unless the 1st … | |
Re: [QUOTE]File "./firstpython", line 6, in <module> input() File "<string>", line 0 [/QUOTE] You want to use raw_input() for the Python version you are using, or enter an integer. | |
Re: [QUOTE]Can somebody tell me why my programm doesn't work and what i can do[/QUOTE]Not without more info. Please include the traceback message at a minimum, with a simple explanation of what isn't working. | |
Re: [CODE]if BMI < 19: print " You are currently underweight" elif BMI >= 19: print " You are in a healthy weight range"[/CODE]You will never get past these two statements as they cover every possibility. Note also, that the second "elif BMI >= 19:" is not necessary as after the … | |
Re: You can use a one to one dictionary "Ä…" --> "a" or use the ord/decimal value if there are codec conversion problems. A decimal value conversion dictionary would be something like: [code] conv_dict = {} conv_dict[ord("Ä…")] = "a" # # and to convert test_ch = "Ä…" if ord(test_ch) in conv_dict: … | |
Re: [QUOTE]I know there is a better way to write that last line, but I'm too lazy to look into it[/QUOTE]I think you could convert to a list and just pass a pair of index counters, but it is more than I want to do as well. | |
Re: At the very least you should test a program before posting the code here. If you test the code posted I think you will find that it does not work as one would expect it to. [QUOTE] if a student passes the exam, but fails the unit by not more … | |
Re: Can you feed HTMLParser one record at a time until the data is found? It would depend on the data type of course (i;m not an HTMLParser user either). [CODE]while not myparser.found: ctr += 1 myparser.feed(info[ctr]) [/CODE] | |
Re: There is something terribly wrong if a 200 element list (10x20) takes that long to run. To answer your question, you can use a dictionary of tuples to get better performance. For example: medium[k[0]][k[1]] = time becomes medium_dict[ (k[0], k[1]) ] = time The simpliest way to time something is … | |
Re: Start by reading the input file (and printing some or all of it's contents to make sure). Post the code used to read and print the file here and we will help you format the output file. Generally speaking, word questions yield word responses and questions with code yield code … | |
Re: Note the name of the function: num_even_digits It works correctly. You are calling the wrong function. | |
Re: Try running it using "python program_name". You don't have anything in the file to tell the OS that it should use the python interpreter when running it. "import os" is not a valid bash statement (or a MS Windows statement). | |
Re: Use a function. [CODE]def download_url(channel_num): url = 'http://192.168.1.6:8008/schedule.html?channel=%s' % (channel_num) texto = urllib.urlopen(url).read() index = texto.find('<td class="topaligned "><div class="withmargin nowrap"') h1 = index+55 index = texto[h1:].find('><span class="title">') pi1 = h1 + index + 21 index = texto[pi1:].find('</span><br') pf1 = pi1 + index index = texto[pf1:].find('<td class="topaligned "><div class="withmargin nowrap"') h2 … | |
Re: [QUOTE]tracking.objects() returns a list of objects[/QUOTE] If it does return a list then you would use allobjs.append(obj[0]) allobjs.append(obj[1]) or allobjs.append(tacking.objects[0]) etc. We here have no way of knowing what obj[0] contains. A little more info is necessary as you seem to be using a list of classes but that is … | |
Re: [CODE]def main(): maze= open('maze.txt','r+') for line in maze: line = line.strip() print line maze.close() print start(maze,x,y) print maze[y][x] [/CODE]This code won't run. You don't call main() and neither maze, x, or y are defined before calling the start(maze, x, y) function. "How To Think Like A Computer Scientist" is a … | |
Re: Check itertools' product. [CODE]import itertools list_1 = [1, 2, 3] list_2 = [4, 5, 6] x = itertools.product(list_1, list_2) for y in x: print y """ My result (1, 4) (1, 5) (1, 6) (2, 4) (2, 5) (2, 6) (3, 4) (3, 5) (3, 6) """ [/CODE] | |
Re: You should use Python's sort() function for lists. In any case, "doesn't work" is not descriptive enough. Include some test input, your output, and the desired output if you want to write the sort code yourself. In addition to what Gribouillis said, you have it backwards. (Please don't use "i", … | |
Re: Use some kind of a switch that you turn on after the first instance is found. [Code]import fileinput string_found = False for line in fileinput.FileInput("text.txt", inplace=1): if (not string_found) and ("hello" in line): line=line.replace("hello","hello2") print line string_found = True [/CODE] | |
Re: You'll have to post the code for my_function(a, b, c, d) or whatever it is called. This statement file.write(my_function(a, b, c, d)) would write the return value. Does the function return a value, and if so, what does it return? | |
Re: This is where you run hit() for every square. [CODE] for i in range(self.y): for j in range(self.x): self.square[i][j]['command'] = self.hit(i, j)[/CODE]Print i and j if you want to check it. Also, self.hit(i, j) does not return anything so self.square[i][j]['command'] will always be 'None'. | |
Re: String formatting is a tool you want to get to know. [url]http://diveintopython.org/native_data_types/formatting_strings.html[/url] [CODE]import datetime now = datetime.datetime.today() url = 'http://samplewebsite/example/example&startdate=' url += '%d%02d%02d&enddate=%d%02d%02d&market_id=X' % \ (now.year, now.month, now.day, now.year, now.month, now.day) print url [/CODE] |
The End.