Re: This should be a simple question...

2009-03-09 Thread Tim Chase
Steven D'Aprano wrote: Tim Chase wrote: If the constants don't actually share any conceptual commonality, then SteveH is right, that they really should just be globals. Surely that's backwards? If the constants don't share any conceptual commonality, they should be kept independent in the func

Re: This should be a simple question...

2009-03-09 Thread Steven D'Aprano
Tim Chase wrote: > If the constants don't actually share any conceptual commonality, > then SteveH is right, that they really should just be globals. Surely that's backwards? If the constants don't share any conceptual commonality, they should be kept independent in the functions and not made glo

Re: This should be a simple question...

2009-03-08 Thread Steve Holden
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

Re: This should be a simple question...

2009-03-06 Thread andrew cooke
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

Re: This should be a simple question...

2009-03-06 Thread Steven D'Aprano
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 t

Re: This should be a simple question...

2009-03-06 Thread Terry Reedy
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 setti

Re: This should be a simple question...

2009-03-06 Thread Tim Chase
As Diez suggests, if you don't want to litter your global namespace, use a class: class Foo: x = 1 b = 2 @classmethod def A(cls, *args, **kwargs): do_stuff_with(Foo.x, Foo.b, args, kwargs) @classmethod def B(cls,*args, **kwargs): do_other_stuff_with(Foo.x, Fo

Re: This should be a simple question...

2009-03-06 Thread Steve Holden
Tim Chase 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 wan

Re: This should be a simple question...

2009-03-06 Thread Tim Chase
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 variable

Re: This should be a simple question...

2009-03-06 Thread andrew cooke
Neal Becker wrote: > What if I had: > > my_obj = common_variables() > That set all these attributes, but then with function A I inject them into > A's scope (shouldn't be too hard to do, I think)? "DRY" is a shorthand for people to remember, but it's not a direct law. i am worried that you are tr

Re: This should be a simple question...

2009-03-06 Thread Neal Becker
Bruno Desthuilliers wrote: > Neal Becker a écrit : >> 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 >> ... >>

Re: This should be a simple question...

2009-03-06 Thread Bruno Desthuilliers
Neal Becker a écrit : 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 se

Re: This should be a simple question...

2009-03-06 Thread Diez B. Roggisch
Neal Becker schrieb: 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 set

Re: This should be a simple question...

2009-03-06 Thread andrew cooke
if the values are related in meaning then it seems possible that they should be attributes on an object. in which case you would use an instance of the object in both cases and set the values in the objects constructor. if they are not related in meaning then you're not really repeating yourself

This should be a simple question...

2009-03-06 Thread Neal Becker
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