[Tutor] How can I make Python Shell see new version offunctionsubroutine?

Alan Gauld alan.gauld at freenet.co.uk
Mon Feb 20 00:43:59 CET 2006


>>> import "c:\\math\\factoring\\factor30.py"

Just use

>>> import factor30

the file will need to be in Pythons search path.

The easiest way is to use a single folder for all your code.

the folder called site-packages should be included by default 
so you might like to use that. Alternatively you can use another 
one and add that folder to an environment vartiable 
called PYTHONPATH

> Could you explain this more.   I'm not compiling or recompiling 
> the function subroutine.

Actually you are. When python imports a file (foo.py say) it compiles 
it into bytecode (and creates a file called foo.pyc in the process).

Reload makes sure you get the latest updated version.

reload(foo)

Alan G.


More information about the Tutor mailing list