[Tutor] An unknown error in my program

2011-12-25 Thread daedae11
The following program has an error : new += lists[int(j)]+-; UnboundLocalError: local variable 'new' referenced before assignment But when I put the sentence new = '' in the main() function, the program run normally. Please tell me why? Isn't

Re: [Tutor] An unknown error in my program

2011-12-25 Thread Joel Goldstick
On Sun, Dec 25, 2011 at 5:18 AM, daedae11 daeda...@126.com wrote: The following program has an error :   new += lists[int(j)]+-; UnboundLocalError: local variable 'new' referenced before assignment But when I put the sentence  new = '' in the main()

Re: [Tutor] An unknown error in my program

2011-12-25 Thread Lie Ryan
On 12/25/2011 09:46 PM, Joel Goldstick wrote: You can either move the stuff at the top of your program into main, or you could pass the outer new into main as a parameter:main(new): the third alternative is to use the global keyword, e.g. # declare a global named 'new' new = 0 def

Re: [Tutor] An unknown error in my program

2011-12-25 Thread Joel Goldstick
On Sun, Dec 25, 2011 at 6:00 AM, Lie Ryan lie.1...@gmail.com wrote: On 12/25/2011 09:46 PM, Joel Goldstick wrote: You can either move the stuff at the top of your program into main, or you could pass the outer new into main as a parameter:    main(new): the third alternative is to use the

Re: [Tutor] question about the build-in function reversed in Python2.5

2011-12-25 Thread Steven D'Aprano
daedae11 wrote: The build-in function reversed() in Python2.5 returns a iterator. But I don't know how to use the iterator. Please give me a simple example about how to use bulid-in function reversed() to reverse a list. You use the iterator the same way you would any other iterator: * in

Re: [Tutor] An unknown error in my program

2011-12-25 Thread Alan Gauld
On 25/12/11 10:18, daedae11 wrote: The following program has an error : new += lists[int(j)]+-; UnboundLocalError: local variable 'new' referenced before assignment Others have answered the question for you however there are two additional points to make: 1) Always send the complete erroir

Re: [Tutor] insert queries into related tables referencing foreign keys using python

2011-12-25 Thread Monte Milanuk
On 12/24/2011 11:13 PM, Lie Ryan wrote: Querying .lastrowid is pretty much safe as long as you don't use a single cursor from multiple threads. The .lastrowid attribute belongs to a cursor, so write operations from one cursor would not affect the .lastrowid of other cursors. However, note that

Re: [Tutor] PYTHONPATH (Mac OS X)

2011-12-25 Thread Stayvoid
Hey there! I'm reading Lutz's Learning Python. Here is some code from the book. There is a module called lcclient_lutz.py: from lengthcounter_lutz import countLines, countChars print countLines('lengthcounter_lutz.py'), countChars('lengthcounter_lutz.py') And there is another one called

Re: [Tutor] PYTHONPATH (Mac OS X)

2011-12-25 Thread Alan Gauld
On 25/12/11 22:55, Stayvoid wrote: There is a module called lcclient_lutz.py: from lengthcounter_lutz import countLines, countChars print countLines('lengthcounter_lutz.py'), countChars('lengthcounter_lutz.py') countChars('lengthcounter_lutz.py') File