On Mon, May 30, 2011 at 4:01 AM, Chris Rebert <c...@rebertia.com> wrote:
> def foo():
>    print bar
>    bar = 42
>
> foo()
>
> ===>
> Traceback (most recent call last):
>  File "<stdin>", line 1, in <module>
>  File "<stdin>", line 2, in foo
> UnboundLocalError: local variable 'bar' referenced before assignment

Wow

I thought it basically functioned top-down. You get a different error
on the print line if there's a "bar = 42" *after* it. This could make
debugging quite confusing.

Guess it's just one of the consequences of eschewing variable
declarations. Sure it's easier, but there's complications down the
road.

Chris Angelico
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to