undesired traceback

Rob Hooft rob at hooft.net
Mon Aug 14 03:06:44 EDT 2000


>>>>> "C" == Courageous  <jkraska1 at san.rr.com> writes:

 >> > why is this code giving me a traceback? (TypeError: No arguments
 >> expected) class Foo: def __init__(): pass f = Foo()

 >> def __init__(self):

 C> To make this more clear, f = Foo() is looking for a function
 C> defined as "def __init__(self):...", but the one it found was "def
 C> __init__():...". 

Yikes, that is a horribly C++ way of expressing it. In C++ one can
have different functions with the same name. In python it is more like

f = Foo() looks for the class Foo, allocates room for a new instance,
makes "f" point to it, looks for the class attribute "__init__", finds
Foo.__init__ (there can be only one), and calls Foo.__init__(f,<all the
rest of the arguments, which in this case is nothing>)

Rob

-- 
=====   rob at hooft.net          http://www.hooft.net/people/rob/  =====
=====   R&D, Nonius BV, Delft  http://www.nonius.nl/             =====
===== PGPid 0xFA19277D ========================== Use Linux! =========



More information about the Python-list mailing list