I want to implement a class inherit from built-in class list and override a method, when I get an instance of this class, I can return a custom data, is it possible?
class MyList(list):
def the_method(self):
# do some thing
return [1, 2]
inst = MyList()
print inst # [1, 2]
Usually when I print an instance of class I will get 'xxx object at 0x0000000002D92358', but if I print an instance of class which inherit from list, I will get a list output, how python do that?