mixins and new style classes
mk
mrkafk at gmail.com
Wed Feb 17 13:00:45 EST 2010
>>> class Person(object):
... pass
...
>>> class Friendly(object):
... def hello(self):
... print 'hello'
...
>>>
>>> Person.__bases__ += (Friendly,)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: Cannot create a consistent method resolution
order (MRO) for bases object, Friendly
But it works for old-style classes:
>>> class Person:
... pass
...
>>> class Friendly:
... def hello(self):
... print 'hello'
...
>>>
>>> p = Person()
>>>
>>> Person.__bases__ += (Friendly,)
>>>
>>> p.hello()
hello
Python is 2.6.1.
More information about the Python-list
mailing list