[IPython-user] interactive help question
Fernando Perez
Fernando.Perez at colorado.edu
Tue Mar 2 13:33:10 CST 2004
Arnd Baecker wrote:
> When I do the following on a "normal" python prompt
> ##############
> def add_xy(x,y):
> """return sum of x and y
> """
> return(x+y)
>
> help(add_xy)
> ##############
>
> I get the expected help.
> However for Ipython I end up with a KeyError.
No, it's not an ipython thing. Check the behavior with a _clean_ python vs
ipython session, where you have just started. I did a bunch of tests, and the
problem is actually caused by scipy. What I found is that, if I am in a
session where scipy has been previously brougth in via @run, or in python via
'from foo import *', where foo.py has an 'import scipy', then the kind of
help() call you show indeed fails. I have seen both the error you mention and
a different one.
Here is an example, from a _plain_ python shell, not ipython:
>>> from Operator import * # Operator.py does an 'import scipy'
>>> def foo():
... 'a docstring'
... pass
...
>>> help(foo)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib/python2.2/site-packages/scipy_base/ppimport.py", line 258,
in __call__
return _pydoc.help(*new_args, **kwds)
File "/usr/lib/python2.2/pydoc.py", line 1510, in __call__
self.help(request)
File "/usr/lib/python2.2/pydoc.py", line 1546, in help
else: doc(request, 'Help on %s:')
File "/usr/lib/python2.2/pydoc.py", line 1338, in doc
module = inspect.getmodule(object)
File "/usr/lib/python2.2/inspect.py", line 363, in getmodule
modulesbyfile[getabsfile(module)] = module.__name__
File "/usr/lib/python2.2/inspect.py", line 344, in getabsfile
return os.path.normcase(
File "/usr/lib/python2.2/inspect.py", line 329, in getsourcefile
filename = getfile(object)
File "/usr/lib/python2.2/site-packages/scipy_base/ppimport.py", line 268,
in _inspect_getfile
object = object._ppimport_module
File "/usr/lib/python2.2/site-packages/scipy_base/ppimport.py", line 222,
in __getattr__
module = self._ppimport_importer()
File "/usr/lib/python2.2/site-packages/scipy_base/ppimport.py", line 200,
in _ppimport_importer
module = __import__(name,None,None,['*'])
File "/usr/lib/python2.2/site-packages/scipy/xplt/__init__.py", line 47, in ?
from Mplot import *
File "/usr/lib/python2.2/site-packages/scipy/xplt/Mplot.py", line 46, in ?
_user_path = _getdir()
File "/usr/lib/python2.2/site-packages/scipy/xplt/Mplot.py", line 41, in
_getdir
if not weave.catalog.is_writable(path):
File "/usr/lib/python2.2/site-packages/scipy_base/ppimport.py", line 223,
in __getattr__
return getattr(module, name)
AttributeError: 'module' object has no attribute 'catalog'
So in this case, blame scipy's ppimport magic for breaking the help system,
not my poor ipython :)
Cheers,
f
More information about the IPython-user
mailing list