I "think" global is broken

Brian Quinlan brian at sweetapp.com
Wed Nov 6 17:24:26 EST 2002


[stuff sniped]
> Am I missing something?

I don't think that you fully understand assignment works in Python.
Unfortunately, I'm not smart enough to explain this, except to say that
assignment is just a name binding/rebuilding operation. Here is an
example:

>>> from math import sin
>>> import math
>>> sin == math.sin 
1 # because the name "math.sin" and "sin" are bound to the same object
>>> sin = math.cos
>>> sin == math.sin
0 # because the name "sin" was rebound to a different object, but
math.sin
  # was untouched

Some tips for your code:
1. never use from module import *, it's evil
2. just use import test
3. you can change test._trace by using:

test._trace = <value>

Cheers,
Brian





More information about the Python-list mailing list