[Tutor] __init__ for class instantiation?
Wed Apr 30 12:48:06 2003
>Monday, April 28, 2003, 9:26:40 PM, Zak Arntson wrote:
> I created a new class, and defined __new__, but it doesn't get called from
> Python, as far as I can tell. Here's my code:
> class C:
> def __new__ (cls):
> print (cls)
> Even when I create the first instance (d = C()), I don't get any output.
I may be mistaken here, but I believe that __new__ would only apply to
new-style classes, not old-style ones. This means that in Python 2.2,
you need to derive your class from object:
I'm not sure if new-style classes are the default in 2.3 or not, but
explicitly deriving from object shouldn't be a problem there.