[SciPy-user] help and lazy-import (?)
Arnd Baecker
arnd.baecker at web.de
Mon Mar 1 16:20:02 CST 2004
Hi,
On Fri, 27 Feb 2004, Arnd Baecker wrote:
> On Fri, 27 Feb 2004, Pearu Peterson wrote:
> > On Fri, 27 Feb 2004, Arnd Baecker wrote:
> >
> > > there there seems to be something weird
> > > going on when trying to access help in the following way
> > >
> > > >>> import scipy
> > > >>> help("scipy.linalg")
> > > Help on instance of _ModuleLoader in scipy:
> > >
> > > scipy.linalg = <module 'scipy.linalg' from '/opt/python/lib/pyt...
> > > e-packages/scipy/linalg/__init__.pyc' [imported]>
> > >
> > > Doing another
> > > >>> help("scipy.linalg")
> > >
> > > one gets the expected help.
> > But in a traditional Python prompt
> >
> > >>> import scipy
> > >>> help("scipy.linalg")
> >
> > I get expected help. This is because ppimport redefines built-in help:
> >
> > >>> help
> > Type help () for interactive help, or help (object) for help about object.
> > >>> help.__module__
> > 'scipy_base.ppimport'
we have had a further look into this and the status is as follows
- setting postpone_import = 0 in (for example)
scipy/xplt/info_xplt.py
gives
>>> import scipy
Traceback (most recent call last):
[...]
from basic import *
File "/opt/python/lib/python2.3/site-packages/scipy/special/basic.py",
line 10, in ?
from scipy import factorial
ImportError: cannot import name factorial
We thought that setting `postpone_import = 0` means that the import
of this module is not postponed so that the doc string should be
available from the first call to help("scipy.xplt").
Is this idea/approach just wrong ?
- We found that for
>>> import scipy
>>> help(scipy.xplt)
the correct documentation is visible already on the first
invokation of help.
(In contrast to
>>> import scipy
>>> help("scipy.xplt")
)
Using the source to ppimport.py this is clear as
in the first case the module is imported (in class _Helper)
before calling the original _pydoc.help.
However, for a string there is no corresponding "ppimport"
attribute and it gets passed directly to _pydoc.help
Just to be sure that we understand things correctly:
Is it true that the actual import in the second case,
i.e. help("scipy.xplt"), is done when __repr__ from the class
_ModuleLoader is called via the "normal" pydoc?
And by this the doc string is available for the following
help("scipy.xplt"), right?
To us it seems to boil down to the question if there is
a good way to import the corresponding module for the
request help("scipy.xplt") in a similar way as it is done
for help(scipy.xplt)?
(Changing __repr__ to also output the docstring sounds like a
horrible hack ..., i.e. there should be a better way)
Many thanks in advance for any suggestions/pointers/...,
Ulf Lorenz, Arnd Baecker
More information about the SciPy-user
mailing list