Syntactic pain.. :P

Magnus L. Hetland mlh at idt.ntnu.no
Mon Sep 6 10:30:13 EDT 1999


Markus Stenberg <mstenber at cc.Helsinki.FI> writes:

> 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 ..


I'm probably missing your point here, but... What about:

  class Bar(Foo):
      def __init__(self, a1, a2, a3="x", a4="y"):
          Foo.__init__(self, a1, a2, a4, a4)
      # ...

AFAIK, this is the normal way of doing it... (Which may of course
imply that I missed some special purpose to your obscure thing... Or
maybe I have fuddled something with the keyword stuff... The result of
the defaults should be the same...)
--

  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