lots of similar classes?
Beni Cherniavsky
cben at techunix.technion.ac.il
Mon Jan 20 10:34:08 EST 2003
On 2003-01-20, boncelet wrote:
> class Super:
> def __init__(self,name,lots_of_other_arguments):
> self.name=name
> <<set rest of arguments, etc>>
>
> class A(Super):
> def __init__(self,name='a',lots_of_other_arguments):
> Super.__init__(self,name,lots_of_other_arguments)
>
> There will be lots of these, eg., A, B, C etc. Most of these will
> differ only in the name argument.In a few, I might want to use only
> a subset of the "other arguments".
>
> My problem is rewriting the "lot_of_other_arguments" over and over
> again seems wasteful, error-prone, and fragile.Is there a better
> way?
>
Besides using ``**kwargs``, if the only difference is the default value of
`name`, consider getting it from a class attribute (set in each subclass)
and not overriding __init__ at all.
--
Beni Cherniavsky <cben at tx.technion.ac.il>
There is an Excel spreadsheet here. Do you want to open it? y
There was a grid bug in the spreadsheet. The grid bug bites.
More information about the Python-list
mailing list