[IPython-user] IPython and __del__

daishi at egcrc.net daishi at egcrc.net
Tue Nov 29 16:10:39 CST 2005


Hi,

I'm encountering some behavior that I don't understand.
I think it is a bug, but I'd be happy to be enlightened
otherwise.

Consider the following deltest.py:

---
class A(object):
     def __init__(self):
         print 'init'
     def __del__(self):
         print 'del'

#a = A()
---

(The last line is intentionally commented out for now).
This gives the following interactive session:

---
% ipython
Python 2.4.2 (#1, Nov 10 2005, 17:03:41)
Type "copyright", "credits" or "license" for more information.

IPython 0.6.16.svn -- An enhanced Interactive Python.
?       -> Introduction to IPython's features.
%magic  -> Information about IPython's 'magic' % functions.
help    -> Python's own help system.
object? -> Details about 'object'. ?object also works, ?? prints more.

In [1]: import deltest

In [2]: a = deltest.A()
init

In [3]: ^D
Do you really want to exit ([y]/n)? y
%
---

(Note that 'del' is not printed upon exit).
Contrast this with the regular python session:

---
% python
Python 2.4.2 (#1, Nov 10 2005, 17:03:41)
[GCC 4.0.1 20050727 (Red Hat 4.0.1-5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> import deltest
 >>> a = deltest.A()
init
 >>> ^D
del
%
---

What's more odd (for me), is that if I now un-comment
the last line and create the A() object in deltest,
the result is "as expected":

---
% ipython
Python 2.4.2 (#1, Nov 10 2005, 17:03:41)
Type "copyright", "credits" or "license" for more information.

IPython 0.6.16.svn -- An enhanced Interactive Python.
?       -> Introduction to IPython's features.
%magic  -> Information about IPython's 'magic' % functions.
help    -> Python's own help system.
object? -> Details about 'object'. ?object also works, ?? prints more.

In [1]: import deltest
init

In [2]: ^D
Do you really want to exit ([y]/n)? y
del
%
---

Any insight into what's going on would be appreciated,
Thanks in advance,
d




More information about the IPython-user mailing list