How to call functions with list and keyword arguments?

John Z. Smith jzsmith at optonline.net
Wed Nov 26 14:51:06 EST 2003


Thanks. I didn't event know that's legal syntax. Just checked the tutorial
and reference
manual but didn't find it. Could you point me to it? Thanks again.

"anton muhin" <antonmuhin.REMOVE.ME.FOR.REAL.MAIL at rambler.ru> wrote in
message news:bq2iog$ak8$1 at news.peterlink.ru...
> 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 ;)
>
> hth,
> anton.
>






More information about the Python-list mailing list