[IPython-user] Is ipython too nosy?
Fernando Perez
fperez.net@gmail....
Wed Feb 28 20:52:23 CST 2007
Hey Alex,
On 01 Mar 2007 01:20:01 +0000, Alexander Schmolck <a.schmolck@gmx.net> wrote:
> Hi,
>
> I would have expected that ipython's (default) policy when the user enters a
> line that constitutes a valid python expression and presses return would be to
> evaluate the whole expression and not attempt any form of introspection on any
> of the constituents.
Life is complicated :) I don't have time right now for a detailed
discussion, unfortunately, but could you please try SVN trunk (r >=
2122)? Its behavior should be a LOT better than before (attribs.py
contains your little class definition):
tlon[test]> ip
Python 2.4.4c1 (#2, Oct 11 2006, 21:51:02)
Type "copyright", "credits" or "license" for more information.
IPython 0.7.4.svn.r2120 -- 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]: run attribs.py
getattr: bar
In [2]: f.this('is bad')
getattr: this
Out[2]: 'nada'
In [3]: f.plot([1,2,3], '-o')
getattr: plot
Out[3]: 'nada'
Note that all kinds of things can trigger getattr, even outside of ipython:
tlon[test]> python
Python 2.4.4c1 (#2, Oct 11 2006, 21:51:02)
[GCC 4.1.2 20060928 (prerelease) (Ubuntu 4.1.1-13ubuntu5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> execfile('attribs.py')
getattr: bar
like calling dir():
>>> dir(f)
getattr: __members__
getattr: __methods__
['__class__', '__delattr__', '__dict__', '__doc__', '__getattr__',
'__getattribute__', '__hash__', '__init__', '__module__', '__new__',
'__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__',
'__weakref__']
>>>
or hitting TAB (right after 'f.'):
>>> f.getattr: __members__
getattr: __methods__
f.__class__ f.__getattr__ f.__module__ f.__repr__
f.__delattr__ f.__getattribute__ f.__new__ f.__setattr__
f.__dict__ f.__hash__ f.__reduce__ f.__str__
f.__doc__ f.__init__ f.__reduce_ex__ f.__weakref__
So in general it is a good idea to have objects that respond as
robustly as possible to getattr() calls.
However, the points you made were most certainly bugs, and I hope they
are resolved now. Please let me know how it goes for you.
regards,
f
More information about the IPython-user
mailing list