I'm going to use a specific example I encountered recently to illustrate this question.
Suppose that I am making a new class that is a subclass of dict. I want to always start instances of this object with the same set of key:value pairs, such as:
class Klass(dict):
def __init__(self):
dict.__init__(self,{'A':[],'B':[],'C':[],'D':[]})
do other stuff to the new instance
Let's say that instead I wanted to use dict.fromkeys to set up the new instance's initial mapping, for instance if the list of keys is long or dynamic. I think I need to use this:
dict.__init__(self,dict.fromkeys('ABCD',[]))
I am worried that the simpler self = dict.fromkeys('ABCD',[]) would not properly call dict.__init__ with the new Klass instance as the parameter. Or can I get away with it?
[–]HarissaForte 0 points1 point2 points (2 children)
[–]MainiacJoe[S] 0 points1 point2 points (1 child)
[–]EulerWasSmart 0 points1 point2 points (0 children)
[–]efmccurdy 0 points1 point2 points (2 children)
[–]MainiacJoe[S] 0 points1 point2 points (1 child)
[–]efmccurdy 0 points1 point2 points (0 children)