我有这个:
#! /usr/bin/env python
class myclass1(object):
def __new__(cls,arg):
print cls, arg, "in new"
ss = super(object,cls)
print ss, type(ss)
ss.__new__(cls,arg)
# super(object,cls).__new__(cls,arg)
# return object.__new__(cls,arg)
def __init__(self,arg):
self.arg = arg + 1
print self, self.arg, "in init"
if __name__ == '__main__':
m = myclass1(56)
它给出了一个错误:
$ ./newtest.py
<class '__main__.myclass1'> 56 in new
<super: <class 'object'>, <myclass1 object>> <type 'super'>
Traceback (most recent call last):
File "./newtest.py", line 23, in <module>
m = myclass1(56)
File "./newtest.py", line 9, in __new__
ss.__new__(cls,arg)
TypeError: super.__new__(myclass1): myclass1 is not a subtype of super
错误是有效的。我明白了。但是,我现在对文档在此页面上为 __new__ 所说的内容感到困惑:http: //docs.python.org/2.6/reference/datamodel.html#object.__new__
问题:根据上面的文档,我做错了什么。我对文档的理解差距在哪里?