__init__ is the initialiser
Chris Angelico
rosuav at gmail.com
Mon Feb 3 00:49:52 EST 2014
On Mon, Feb 3, 2014 at 4:12 PM, Roy Smith <roy at panix.com> wrote:
> So, what you're saying is when I delete an object, __del__() has both
> been called and not been called?
>>> class Schrodinger:
def __init__(self):
print("Init!")
>>> print(Schrodinger())
Init!
<__main__.Schrodinger object at 0x02B52570>
At this point, __del__ has indeed both been called and not been
called. However, observing its state will force it to collapse:
>>> class Schrodinger:
def __init__(self):
print("Init!")
def __del__(self):
print("Del!")
>>> print(Schrodinger())
Init!
<__main__.Schrodinger object at 0x02B52830>
Del!
If an object falls off the heap and there's no __del__ method to hear
it, does it call __del__?
ChrisA
More information about the Python-list
mailing list