Syntactic pain.. :P
Magnus L. Hetland
mlh at idt.ntnu.no
Wed Sep 8 10:29:11 EDT 1999
Markus Stenberg <mstenber at cc.Helsinki.FI> writes:
> mlh at idt.ntnu.no (Magnus L. Hetland) writes:
>
> Yes, exactly; that's why I'm using Python for rapid prototyping and not
> say, Java or C++ (yeech). I was mainly looking for more elegant way to do
> it, but judging from the replies I got, there was just slight
> beautification available to my approach, and apply still stayed. Oh well.
>
IC... Well - what about a little planning? If you are going to do it
this way, why not add an initialization method without parameters, and
leave the constructor alone? It might work in some cases, and I guess
you could make it work in most...
class Foo:
def __init__(self,a,b,c,d,e,f,g):
# some stuff
self.init()
def init(self): pass
class Bar(Foo):
def init(self):
# some stuff modifying the original constructor
You won't get the parameters directly, but hopefully, they will
somehow (directly or indirectly) be stored in the instance. *Or* you
could pass a dictionary of the parameters as a parameter to init.
And - I guess this would work for further inheritance as well:
class Baz(Bar):
def init(self):
Bar.init(self)
# some more stuff
It seems to me that this does some of the stuff you wanted, and it
doesn't use "apply"... :) (I just hope I didn't bungle something about
the dynamic dispatch in the inheritance here, then...)
--
Magnus Making no sound / Yet smouldering with passion
Lie The firefly is still sadder / Than the moaning insect
Hetland : Minamoto Shigeyuki
More information about the Python-list
mailing list