[Python-Dev] How to suppress instance __dict__?

Michael Hudson mwh at python.net
Mon Mar 24 04:33:08 EST 2003


"Delaney, Timothy C (Timothy)" <tdelaney at avaya.com> writes:

[__init__ vs. __new__]

> Because most of the time we want to work with fully-constructed
> objects. You can't use overridden methods in a constructor - only
> from an initialiser.

What makes you say that?

/>> class C(object):
|..     def __new__(cls):
|..        i = object.__new__(cls)
|..        i.meth()
|..        return i
|..     def meth(self):
|..        print "C"
\__ 
/>> class D(C):
|..     def meth(self):
|..         print "D"
\__ 
->> D()
D
<__main__.D object at 0x820f684>

Doing too much C++ lately?

Cheers,
M.

-- 
31. Simplicity does not precede complexity, but follows it.
  -- Alan Perlis, http://www.cs.yale.edu/homes/perlis-alan/quotes.html




More information about the Python-list mailing list