using identifiers before they are defined
Emile van Sebille
emile at fenx.com
Tue Jun 12 14:17:16 EDT 2012
On 6/12/2012 10:53 AM Julio Sergio said...
<snip>
> So I modified my module:
>
> global something
>
> a = something(5)
>
>
> def something(i):
> return i
>
>
> And this was the answer I got from the interpreter:
>
> ->>> import tst
>
> Traceback (most recent call last):
> File "<stdin>", line 1, in<module>
> File "tst.py", line 12, in<module>
> a = something(5)
> NameError: global name 'something' is not defined
>
>
> Do you have any comments?
python executes each line as it encounters it. a=something(5) as you
have it attempts to bind the label 'a' to the result of something(5)
which has not yet been defined. You seem to want it to compile
everything first, then execute but it doesn't work that way.
Emile
More information about the Python-list
mailing list