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
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
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
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
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
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
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
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
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
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
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
>> ...
>>
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
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
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
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
15 matches
Mail list logo