style and new
Possible Duplicate:
Old style and new style classes in Python
What is the current state of affairs with new-style and old-style classes in Python 2.7? I don't work with Python often but I vaguely remember the issue. The documentation doesn't seem to mention the issue at all: The Python Tutorial: Classes. Do I still need to worry about this? In general should I declare my classes like:
class MyClass:
pass
or?
class MyClass(object):
pass
Always subclass "object". Those are new style classes.
You are ready for python 3 that way.
Things like .super()
work properly that way, should you need them.
You should always use new style classes. New-style classes are part of an effort to unify built-in types and user-defined classes in the Python programming language.
New style classes have several things to offer such as:
Source.
链接地址: http://www.djcxy.com/p/54180.html上一篇: 哪里
下一篇: 风格和新