[IPython-user] import local_module requires reload(local_module)

Alan Brogan ipython@al-got-rhythm....
Thu Jan 24 09:34:27 CST 2008


Hello the list,

I have tried list archives and general Googling, but still cannot figure out
how to crack this one. Hopefully someone on the list can point me towards a
FAQ.

The question is about "import path", that wonder module from Jason
Orendorff. I have modified it to pass all the commands through a logger, and
generally need to import that version of the module. In Python this proceeds
smoothly when I run from the dir containing my version of path.py, see
transcript below. But in ipython I need to import, then reload the path
module. (Again, see transcript below). This reload is also needed when
importing other modules from this directory, so that instead of a simple
"import other" I need to do a "import path; reload(path); import other"
dance.

How do I get over this glitch ?

-- 
Alan

PS: Some transcripts


>>> >>> Python Transcript:

[2007 builder@ie-build-1 builder 0]$ ls path.py
path.py
[2007 builder@ie-build-1 builder 0]$ python
Python 2.4.3 (#2, Sep 18 2006, 21:07:35)
[GCC 4.1.1 20060724 (prerelease) (4.1.1-3mdk)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import path
>>> path.__file__
'path.pyc'
>>>

]]] ]]] IPython Transcript

[2007 builder@ie-build-1 builder 0]$ ls path.py
path.py
[2007 builder@ie-build-1 builder 0]$ ipython
Python 2.4.3 (#2, Sep 18 2006, 21:07:35)
Type "copyright", "credits" or "license" for more information.

IPython 0.7.3 -- 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 path

In [2]: path.__file__
Out[2]: '/usr/lib/python2.4/site-packages/IPython/Extensions/path.pyc'

In [3]: reload(path)
Out[3]: <module 'path' from 'path.pyc'>

In [4]: path.__file__
Out[4]: 'path.pyc'

In [5]:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ipython.scipy.org/pipermail/ipython-user/attachments/20080124/21c94e6a/attachment.html 


More information about the IPython-user mailing list