[Chicago] Using globals across files
Ian Bicking
ianb at colorstudy.com
Wed Mar 29 00:06:09 CEST 2006
Jason Rexilius wrote:
> globals are not across-the-board bad.. abusing them is bad (which
> happens often enough for people to get the idea that they are bad)
> but there are times when a truly global variable (like a counter) is
> usefull.
>
> I am surprised that this type of construct doesn't exist in Python..
Here's how I'd do a counter:
# in some_module.py
import itertools
my_counter = itertools.count()
# in another_module.py
from some_module import my_counter
def foo():
next_value = my_counter.next()
This solves several threading and binding problems that might bite you
later. In Python there's no real global-everywhere variables, for
several reasons besides "globals are bad"; the badness of globals is
actually low on the scale of reasons IMHO.
--
Ian Bicking / ianb at colorstudy.com / http://blog.ianbicking.org
More information about the Chicago
mailing list