I have two classes in my code. first
is the parent, which second
inherits.
class first(object):
def __init(self,**kwargs):
pass
def __setattr__(self,name,value):
self.__dict__[name] = value
class second(first):
def do_something(self):
self.a = 1
self.b = 2
self.c = 3
when I am printing the class second (by e.g. second.__dict__
) I get the unordered dictionary. This is obvious. I want to change this behavior to get an ordered dictionary using the OrderedDict
class, but it does not work. I am changing implementation of first
in the following way:
class first(OrderedDict):
def __init__(self,**kwargs):
super(first,self).__init__(**kwargs)
def __setattr__(self,name_value):
super(first,self).__setattr__(name_value)
I would like to print second
using __dict__
or __repr__
, but I got the unordered dictionary. What should I change?