Christoph Groth wrote:
According to my understanding, if float type's __init__ ignores its
arguments then the value of `arg' above should be ignored. Instead,
the constructed object has the value 12. Where is this 12 passed to
the object being constructed?
To __new__.
class Test(object):
... def __new__(cls):
... print "calling new"
... return object.__new__(cls)
... def __init__(self):
... print "calling init"
... Test()
calling new
calling init
<__main__.Test object at 0xbf491f0c>
...they are both called, but it is constructed in __new__. __new__
returns the object, while __init__ returns nothing. __init__ is actually
called after initialization, because the initialization happens when
object.__new__ is called. Because it is an immutable type, it cannot be
changed after it has been initialized, so __init__ can't thange it.
Gerrit.
--
PrePEP: Builtin path type
http://people.nl.linux.org/~gerrit/c.../pep-xxxx.html
Asperger's Syndrome - a personal approach:
http://people.nl.linux.org/~gerrit/english/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)
iD8DBQFAJnTS6A1yqfkBKlARAsR3AJ4/qeyhDo/ER5ktqoZuaYuEDlcq5gCeOYBp
NEDtLRF92iry2fOLSnKMLM4=
=nfj2
-----END PGP SIGNATURE-----