This should be a simple question...
Terry Reedy
tjreedy at udel.edu
Fri Mar 6 13:29:28 EST 2009
Neal Becker wrote:
> Maybe I'm missing something obvious here
>
> def A (...):
> #set a bunch of variables
> x = 1
> b = 2
> ...
>
> Do something with them
>
> def B (...):
> #set the same bunch of variables
> x = 1
> b = 2
> ...
>
> Do something with them
>
> I want to apply DRY, and extract out the common setting of these variables
> into the local scope of the functions A and B. How to do this? (Other than
> just setting them in the module scope)
Yet another solution:
def ABmaker()
x = 1
b = 2
def A(...): do stuff using x. b, and args
def B(...): ""
return A,B
A,B = ABmaker
tjr
More information about the Python-list
mailing list