[SciPy-User] How to make sure that a module gets re-loaded
Sun Oct 25 07:03:23 CDT 2009
George Nurser wrote:
> 2009/10/24 Gaetan Cesar Koers <email@example.com>:
>> The code I'm working on, in module 'M.py', is located in a directory
>> named 'M'. From the parent of directory 'M', when I do 'import M' or
>> 'reload M', how can I make sure that Python imports/reloads 'M/M.py'?
> There are at least three ways to do this. Below abspath-M is the full
> absolute path to directory M, and relpath-M the relative path
> 1. Add abspath-M to the PYTHONPATH environment variable
> 2. In ipython do
> import sys
> sys.path.append('abspath') OR sys.path.append('relpath')
> [so e.g. if you are running ipython from the parent of M, simply
> 3. Create a file named M.pth in a directory already in sys.path. This
> file should contain the line
> abspath ( or relpath). I put .pth files in my
> $HOME/lib/python2.5/site-packages directory.
> You can find out where your personal site-packages directory is by
> inspecting the path from python or ipython with
> print '\n'.join(sys.path)
> So e.g. if your modules are in /users/xxx/bigproject/M
> and you have a site-packages directory at
> Create a file /users/xxx/lib/python2.5/site-packages/M
> with content (just one line)
> or with content
> Method 3 is cleanest, but allows a python program running from *any*
> directory to access your modules in /users/xxx/bigproject/M, as does
> method 1.
Hi George, thanks for this explanation
And why does adding a directory to sys.path affect the 'reload'
behaviour of the modules in that directory?
More information about the SciPy-User