On 21 August 2011 22:35, D. Guandalino <guandal...@gmail.com> wrote: > >>> class C(object): > ... def __init__(self): > ... pass > ... > >>> C(1) > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > TypeError: __init__() takes exactly 1 argument (2 given) > > I'm having hard times understanding why a TypeError is raised here. > Could you explain? >
The more obvious answer was given by David, but I'd like to also add that the reason why Python complains in this instance with *TypeError* (as opposed to say something like "ArgumentError" or "ValueError" imagining for the moment such things existed) is becuase, looking function objects, fn(a) is type-incompatible with fn(a,b). Differently put, the argument list is part of the type of a function, and the different argument lists makes the expected function and the actual provided incompatible, hence Python raises TypeError. (Note this is somewhat speculative on my part so take it for what it's worth.) Regards Walter
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor