python - Why does this code pass a parameter to a constructor when there is no __init__ method? -


so, reading code online , came across following class definition , i'm little confused;

class myclass(ordereddict):     def __hash__(self):         return hash(tuple(self.iteritems())) 

elsewhere in code there following line;

myclass(my_od) 

where my_od ordered dictionary. question is, how can pass argument class when there no __init__ method? variable being assigned within class? i'm coming java , i'm in java cannot pass argument class without constructor behavior foreign me.

the class myclass inherits ordereddict:

class myclass(ordereddict): 

since myclass doesn't have __init__ method specified, calls init method of ordereddict class. my_od argument constructor gets passed on ordereddict. btw, __init__ not technically constructor.

the purpose of myclass ordereddict computes hash of instances in different way ordereddict does. specifically, ordereddict doesn't have __hash__, that's defined on dicts , in case, hash defined none - dicts un-hashable. myclass changes adds way hash, while rest of functionality same ordereddicts , dicts.


Comments