2,190 Posted Topics

Member Avatar for asthaynian

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 …

Member Avatar for TrustyTony
0
1K
Member Avatar for ChargrO

[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.

Member Avatar for TrustyTony
0
472
Member Avatar for jonb7

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 …

Member Avatar for TrustyTony
0
1K
Member Avatar for pythonNerd159

[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.

Member Avatar for vegaseat
0
123
Member Avatar for jozz3

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 …

Member Avatar for woooee
0
107
Member Avatar for cahram

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" …

Member Avatar for TrustyTony
0
202
Member Avatar for awn

[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 …

Member Avatar for awn
0
580
Member Avatar for sabiut

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): …

Member Avatar for sabiut
0
194
Member Avatar for linuxoidoz

[QUOTE]My question is - should all strings be Python strings[/QUOTE]It's always a good idea to convert to Python strings.

Member Avatar for jcao219
0
134
Member Avatar for dbphydb

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 …

Member Avatar for TrustyTony
0
84
Member Avatar for daviddoria

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.

Member Avatar for daviddoria
0
15K
Member Avatar for freakn_style

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 …

Member Avatar for freakn_style
0
1K
Member Avatar for notuserfriendly

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":" "} …

Member Avatar for woooee
0
509
Member Avatar for Ntsoaki

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 …

Member Avatar for TrustyTony
0
142
Member Avatar for JJBallanger

[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 …

Member Avatar for JJBallanger
0
630
Member Avatar for nsutton

Yo write what you want to keep to a separate file. Start here [url]http://www.greenteapress.com/thinkpython/html/book015.html#toc154[/url]

Member Avatar for nsutton
0
2K
Member Avatar for cyon

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]

Member Avatar for TrustyTony
0
180
Member Avatar for rasizzle

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 …

Member Avatar for woooee
0
367
Member Avatar for pietromarchy

You could probably use subprocess' readline & write. Doug Hellmann has an example here [url]http://blog.doughellmann.com/2007/07/pymotw-subprocess.html[/url]

Member Avatar for pietromarchy
0
539
Member Avatar for LarZ

Try self.Destroy() The wiki has examples [url]http://wiki.wxpython.org/Getting_Started[/url]

Member Avatar for Dixtosa
0
4K
Member Avatar for daviddoria

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]

Member Avatar for woooee
0
155
Member Avatar for pythonnewbie10

[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 …

Member Avatar for TrustyTony
0
154
Member Avatar for sarfrazashfaq

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 …

Member Avatar for leegao
0
244
Member Avatar for StratmanPereida

[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 …

Member Avatar for StratmanPereida
0
185
Member Avatar for pankajpriyam

[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.

Member Avatar for jice
0
101
Member Avatar for vmanes

[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 …

Member Avatar for jwenting
2
174
Member Avatar for theweirdone

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]

Member Avatar for TrustyTony
0
264
Member Avatar for soUPERMan

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.

Member Avatar for soUPERMan
0
86
Member Avatar for pythonnewbie10

[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.

Member Avatar for woooee
0
145
Member Avatar for kjock002

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 …

Member Avatar for TrustyTony
-3
232
Member Avatar for prashanth s j

[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.

Member Avatar for woooee
0
116
Member Avatar for basti!
Re: Plot

[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.

Member Avatar for woooee
-3
178
Member Avatar for ITgirl2010

[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 …

Member Avatar for ITgirl2010
0
214
Member Avatar for kur3k

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: …

Member Avatar for jice
0
670
Member Avatar for jozz3

[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.

Member Avatar for jozz3
0
574
Member Avatar for ITgirl2010

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 …

Member Avatar for woooee
0
115
Member Avatar for Enders_Game

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]

Member Avatar for Enders_Game
0
170
Member Avatar for PhrackSipsin

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 …

Member Avatar for woooee
0
172
Member Avatar for vineshn

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 …

Member Avatar for vineshn
-1
134
Member Avatar for klebron23

Note the name of the function: num_even_digits It works correctly. You are calling the wrong function.

Member Avatar for woooee
0
203
Member Avatar for musturd

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).

Member Avatar for musturd
0
1K
Member Avatar for ultravox

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 …

Member Avatar for ultravox
0
170
Member Avatar for adarshcu

[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 …

Member Avatar for adarshcu
0
203
Member Avatar for adam321

[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 …

Member Avatar for adam321
-2
198
Member Avatar for mattloto

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]

Member Avatar for mattloto
0
277
Member Avatar for Siyabonga Gama

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", …

Member Avatar for woooee
0
79
Member Avatar for froggy1

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]

Member Avatar for froggy1
0
149
Member Avatar for Axel_Carvalho

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?

Member Avatar for Axel_Carvalho
0
132
Member Avatar for toll_booth

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'.

Member Avatar for toll_booth
0
173
Member Avatar for chazut

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]

Member Avatar for chazut
0
6K

The End.