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

Dick Moores rdm at rcblue.com
Sat Jun 28 12:38:43 CEST 2008

At 01:52 AM 6/28/2008, wesley chun wrote:
> > Sorry to be dense, but how, in what way, is a1's l1  different from a2's
> > l1"?  Both are [1,2,3]*100 .
>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 concatenation is really slower than using
>the extend() method.

And in fact, list concatenation seems a bit faster.

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

It does work.

BTW I see that your book has what seems to be a thorough discussion 
of namespaces and variable scopes in chapter 12.



More information about the Tutor mailing list