Basic misunderstanding on object creation

Thomas Rachel nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de
Wed May 13 10:24:27 EDT 2015


Am 13.05.2015 um 15:25 schrieb andrew cooke:
>>>> class Foo:
> ... def __new__(cls, *args, **kargs):
> ... print('new', args, kargs)
> ... super().__new__(cls, *args, **kargs)

> new (1,) {}
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> File "<stdin>", line 4, in __new__
> TypeError: object() takes no parameters

object's __new__() dosn't take any parameters. So call it without arguments:
class Foo:
 def __new__(cls, *args, **kargs):
 print('new', args, kargs)
 super().__new__(cls)
(at least if we know that we inherit from object. Might be that this one 
doesn't work very good with multiple inheritance...)
Thomas


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /