variable declaration
Fredrik Lundh
fredrik at pythonware.com
Tue Feb 8 05:47:21 EST 2005
Peter Otten wrote:
>> executed. the compiler handles "global" and "from __future__", everything
>> else is done at runtime.
>
> and __debug__, too, it seems:
you left out the "python -O" line.
>>>> __debug__
> False
>>>> def f():
> ... if __debug__:
> ... global x
> ... x = 42
> ...
>>>> f()
>>>> x
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> NameError: name 'x' is not defined
yup, but unlike the two others, that's a CPython -O implementation issue.
(I'd say bug, in this case).
neither standard CPython (without -O) nor Jython behave this way.
</F>
More information about the Python-list
mailing list