[Chicago] Using globals across files

Michael Tobis mtobis at gmail.com
Wed Mar 29 00:44:14 CEST 2006


Yeah, oops, thanks.

I guess this has its drawbacks, though a litgtle less severe than Ian says.

If you take care to mutate a mutable rather than reassigning its name,
you get what you want, sort of.

tobis$ cat myglob.py
a = [42]

def chga():
   global a
   a.append(1)

tobis$ python
... Type "help", "copyright", "credits" or "license" for more information.
>>> from myglob import *
>>> a
[42]
>>> chga()
>>> a
[42, 1]
>>>

But just one a = a + [1,2,3] and your a is out of scope forever in a
hard-to-spot way...

This is a (yet another!) case where it seems like a non-rebindable
name wants to happen!

mt


More information about the Chicago mailing list