[Tutor] "local variable 'l1' referenced before assignment"

wesley chun wescpy at gmail.com
Sat Jun 28 10:52:23 CEST 2008


> Sorry to be dense, but how, in what way, is a1's l1  different from a2's
> l1"?  Both are [1,2,3]*100 .

dick,

alan and everyone else are correct, but let me just put it as simply as this:

- in a1(), you're accessing l1 as a global variable
- in a2(), you're making l1 a local variable but trying to get its
value before you've assigned anything to it.

i can see what you're trying to do however... a noble effort: answer
the question of whether list contatenation is really slower than using
the extend() method.

anyway, if you make alan's tweak and slip "global l1" as the 1st line
in a2(), it should work better and be a more equivalent comparison.

best of luck!
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2007,2001
 http://corepython.com

wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com


More information about the Tutor mailing list