Created
July 20, 2015 21:00
-
-
Save jsocol/226fa155677a682929f4 to your computer and use it in GitHub Desktop.
why new-style classes?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> class NewStyle(object): | |
... def foo(self): | |
... return 'foo' | |
>>> class OldStyle(): | |
... def foo(self): | |
... return 'foo' | |
>>> dir(NewStyle) | |
['__class__', | |
'__delattr__', | |
'__dict__', | |
'__doc__', | |
'__format__', | |
'__getattribute__', | |
'__hash__', | |
'__init__', | |
'__module__', | |
'__new__', | |
'__reduce__', | |
'__reduce_ex__', | |
'__repr__', | |
'__setattr__', | |
'__sizeof__', | |
'__str__', | |
'__subclasshook__', | |
'__weakref__', | |
'foo'] | |
>>> dir(OldStyle) | |
['__doc__', '__module__', 'foo'] | |
>>> n = NewStyle() | |
>>> o = OldStyle() | |
>>> type(n) | |
__main__.NewStyle | |
>>> type(o) | |
instance | |
>>> class OldChild(OldStyle): | |
... def foo(self): | |
... return super(OldChild, self).foo() + 'bar' | |
>>> oc = OldChild() | |
>>> oc.foo() | |
TypeError: must be type, not classobj |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://stackoverflow.com/a/19950198/29654