Re: handling many default values

2006-11-14 Thread Michele Simionato
Gabriel Genellina wrote: > At Monday 13/11/2006 13:33, Michele Simionato wrote: > > >Alan Isaac wrote: > > > Also, as an aside, no one objected to using > > > self.__dict__.update(kwargs) > > > in the __init__ function of the parameter holding class. > > > >It is a common trick, also shown in t

Re: handling many default values

2006-11-13 Thread Gabriel Genellina
At Monday 13/11/2006 13:33, Michele Simionato wrote: Alan Isaac wrote: > Also, as an aside, no one objected to using > self.__dict__.update(kwargs) > in the __init__ function of the parameter holding class. It is a common trick, also shown in the Python cookbook, IIRC. If you are anal about

Re: handling many default values

2006-11-13 Thread Michele Simionato
Alan Isaac wrote: > Also, as an aside, no one objected to using > self.__dict__.update(kwargs) > in the __init__ function of the parameter holding class. It is a common trick, also shown in the Python cookbook, IIRC. If you are anal about double underscores, you can also use vars(self).update

Re: handling many default values

2006-11-11 Thread Alan Isaac
"Steven D'Aprano" wrote > (1) If there really is no alternative to a class with many arguments; > (2) and instances can vary those arguments unpredictably; > then this approach seems reasonable to me. But I really suggest you > rethink your class design. Thanks to all who replied and to George for

Re: handling many default values

2006-11-11 Thread George Sakkis
Ben Finney wrote: > "Alan Isaac" <[EMAIL PROTECTED]> writes: > > > There are *many* parameters, and the list can change, so I want to > > avoid listing them all in the Param class's __init__ function, using > > the strategy above. > > > > Q1: Is this approach reasonable? > > (This is a newbie

Re: handling many default values

2006-11-11 Thread Ben Finney
"Alan Isaac" <[EMAIL PROTECTED]> writes: > There are *many* parameters, and the list can change, so I want to > avoid listing them all in the Param class's __init__ function, using > the strategy above. > > Q1: Is this approach reasonable? > (This is a newbie question about unforseen hazards.)

Re: handling many default values

2006-11-11 Thread pgarrone
Alan Isaac wrote: > > At Friday 10/11/2006 14:11, Alan G Isaac wrote: > > >class Params: > > > def __init__(self,**kwargs): > > > #set lots of default values > > > ... > > > #set the deviations from defaults > > > self.__dict__.update(kwargs) > > > > > >Is

Re: handling many default values

2006-11-11 Thread Steven D'Aprano
On Fri, 10 Nov 2006 17:11:24 +, Alan G Isaac wrote: > My class MyClass reuses many default parameters > with a small number of changes in each instance. Let me see that I understand. Are you doing something like this? # Class takes a lot of arguments a = MyClass(0, 1, 2, 3, 4, 5, ..., 99) #

Re: handling many default values

2006-11-11 Thread Alan Isaac
> At Friday 10/11/2006 14:11, Alan G Isaac wrote: > >class Params: > > def __init__(self,**kwargs): > > #set lots of default values > > ... > > #set the deviations from defaults > > self.__dict__.update(kwargs) > > > >Is this a reasonable approach overall? >

Re: handling many default values

2006-11-10 Thread Gabriel Genellina
At Friday 10/11/2006 14:11, Alan G Isaac wrote: My class MyClass reuses many default parameters with a small number of changes in each instance. For various reasons I decided to put all the parameters in a separate Params class, instances of which reset the default values based on keyword argume

handling many default values

2006-11-10 Thread Alan G Isaac
My class MyClass reuses many default parameters with a small number of changes in each instance. For various reasons I decided to put all the parameters in a separate Params class, instances of which reset the default values based on keyword arguments, like this: class Params: def __init__(se