Python version: "'2.7.3 (default, April 10, 2013 06:20:15) \ n [GCC 4.6.3]'"
I have it:
>>> class testclass1(object): ... pass ... >>> class testclass2(object): ... def __init__(self,param): ... pass ... >>> a = object.__new__(testclass1, 56) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: object.__new__() takes no parameters >>> b = object.__new__(testclass2, 56) >>> b <__main__.testclass2 object at 0x276a5d0>
A bit more fun! Compare with testclass1 results above.
>>> class testclass3(object): ... def __init__(self): ... pass ... >>> c = object.__new__(testclass3, 56) >>> c <__main__.testclass3 object at 0x276a790> >>> c1 = object.__new__(testclass3) >>> c1 <__main__.testclass3 object at 0x276a810>
My question is how (and not why) object__new__ behave differently in these two cases? Also, pay attention to the error, which is misleading in the first case, because in the second case, object.__new__ ultimately takes an argument !.
python object constructor
abc
source share