global, was Re: None assigment
Jeremy Hylton
jeremy at alum.mit.edu
Fri Feb 9 14:13:14 EST 2001
In article <9613mn$9v$1 at news.mathworks.com>,
Joshua Marshall <jmarshal at mathworks.com> wrote:
> Michael Hudson <mwh21 at cam.ac.uk> wrote:
> > Michael Hudson <mwh21 at cam.ac.uk> writes:
>
> >> Which version are you using? They all print 4 for me, and all but
> >> foo() do modify the value of `b'. foo() doesn't because what
follows
> >> an
>
> > OTOH, that was a version that had the PEP 227 code checked into it.
> > With an older version, I see what you see. Wierd.
>
> Sounds like a bug fix.
>
As Tim will explain in a post that hasn't made it to DejaNews yet,
earlier versions of Python did not define the behavior of assignment
before a global statement.
The recent round of compiler changes uses separate passes to determine a
name's scope and to generate code for loads and stores. As a result,
the global statement affects all assignments.
It's unclear what we should happen in this case. It could be an error,
since it's dodgy and the behavior will change with 2.1.
--
-- Jeremy Hylton, <http://www.python.org/~jeremy/>
Sent via Deja.com
http://www.deja.com/
More information about the Python-list
mailing list