[Tutor] Modify inherited methods

Walter Wefft walterwefft at googlemail.com
Wed Apr 28 08:53:06 CEST 2010


Steven D'Aprano wrote:
 > And for guru-level mastery, replace to call to dict.__init__ with ... 
nothing at all, because dict.__init__ doesn't do anything.
 >
 >
 >

(Sorry, should have sent to list).

I don't understand this - it must do something:

class MyDict1(dict):

    def __init__(self, *args, **kw):
        pass

class MyDict2(dict):

    def __init__(self, *args, **kw):
        dict.__init__(self, *args, **kw)


d = MyDict1(y=2)
print d
{}

d = MyDict2(y=2)
print d
{'y': 2}

d = MyDict1({'x': 3})
print d
{}

d = MyDict2({'x': 3})
print d
{'x': 3}

Behaviour is different depending on whether you call the superclass 
__init__ or not.

?




More information about the Tutor mailing list