How to call functions with list and keyword arguments?

anton muhin antonmuhin.REMOVE.ME.FOR.REAL.MAIL at
Wed Nov 26 17:01:21 CET 2003

John Z. Smith wrote:
> Hi,
>    I want to subclass a class (more precisely, optparse.Option). that looks
> like
> class Option:
>   def __init__(self, *opts, **attrs):
>         do_something()
> I want to do something in my __init__ and and also call Option.__init__.
> Then I don't know how to pass the arguments. For example,
> class MyOption:
>    def __init__(self, *opts, **attrs):
>         do_my_own_thing()
>          Option.__init__(self, opts, attrs)
> does not work (and you know why). I figured out some very ugly ways to do
> this
> but I believe there should be an elegant way to pass the argments to
> superclass.

Option.__init__(self, *opts, **attrs) should work. BTW, some purists 
recommend to use super ;)


More information about the Python-list mailing list