This should be a simple question...
andrew cooke
andrew at acooke.org
Fri Mar 6 16:04:24 EST 2009
Steven D'Aprano wrote:
> Steve Holden wrote:
>
>> If x and b are meant to be global than bite the bullet and *make* them
>> global.
>
> Well, there's global, and there's global.
>
> There's global to a few functions in a module, there's global to
> everything
> in a module, and global to an entire application. They're not necessarily
> the same thing.
this is probably drifting a bit far from the original question, but i have
used function scope to hide information "global" to a few functions. the
idea is to use a factory function that generates them all.
def factory():
a = 12
b = 34
def ifamultb(x):
if a == x:
return x * b
else:
return x
def somethinelse(x):
blah blah
(ifamultb, somethinelse) = factory()
that's off the top of my head. you might need to work around python's
stupid scoping rules with hidden params:
def ifamultb(x, a=a):
etc
andrew
More information about the Python-list
mailing list