calling superclass' method with list positional arg

Andrew Dalke dalke at acm.org
Fri Apr 13 06:18:09 EDT 2001


Steven Haryanto:
>class BagOTricks(Bag):
>
>     def __init__(*args):
>         self = args_[0]
>         # do something else first...
>
>         # then pass the items to superclass' constructor
>         apply(Bag.__init__, args_)

I've never seen it written that way.  I've always used

    def __init__(self, *args):
        # do something else first ...

        # this pss the items to superclass' constructor
        apply(Bag.__init__, (self,) + args)

In Python 2.0 you can also do

        Bag.__init__(self, *args)

                    Andrew
                    dalke at acm.org






More information about the Python-list mailing list