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.

?


_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to