Syntactic pain.. :P
Markus Stenberg
mstenber at cc.Helsinki.FI
Mon Sep 6 03:20:27 EDT 1999
As far as I've read, there isn't any way to make this any more .. elegant:
class Foo:
def __init__(self, a1, a2, a3="x", a4="y"): pass
class Bar(Foo):
def __init__(self, *args, **kwargs):
apply(Foo.__init__, tuple([self]+list(args)), kwargs)
#.. do some things ..
Ok, as far as I'm concerned, the initial Foo definition looks clear. Bar
definition looks fine and dandy too, except for the black apply magic. Is
there no more .. hm. novice-readable way, to do subclasses with just
slightly different constructors? (I'm curious about this because although
_I_ know Python fairly well, some people who might need to read my code
might not, and the meaning of that construct is not quite apparent at first
glance)
That (*args,**kwargs) magic someone posted about earlier sounded like a
moderately nice solution (compare that apply stuff to
Foo.__init__(self,*args,**kwargs)), but is there any chance of it showing
up in some Python release?
-Markus Stenberg
--
"The truth is out there." -X-files
"The truth may be out there, but lies are inside your head." -T.Pratchett
More information about the Python-list
mailing list