Re-loading updated modules

F

fileexit

Hi,
Shouldn't python recompile a module if there is a later version of the
code (.py file)? While i am debuging, i always have to exit python and
delete the pyc before every run, then start it again and import the
modules. It seems that this is the only way for it to recompile the
new code.

What is going on? is this normal behaviour? I noticed that on both
Windows and linux (Fedora Core 4, and 5 and RHEL 4)
 
P

Pierre Quentel

Instead of exiting the interpreter, you can use reload() : see the
section "Built-in functions" in the library reference

"reload( module)
Reload a previously imported module. The argument must be a module
object, so it must have been successfully imported before. This is
useful if you have edited the module source file using an external
editor and want to try out the new version without leaving the Python
interpreter. The return value is the module object (the same as the
module argument). "

Pierre
 
F

Fredrik Lundh

fileexit said:
Shouldn't python recompile a module if there is a later version of the
code (.py file)?

it does, when the module is first loaded.
While i am debuging, i always have to exit python and
delete the pyc before every run

deleting the PYC shouldn't be necessary.
then start it again and import the
modules. It seems that this is the only way for it to recompile the
new code.

reload(module)

however, see the caveats on this page:

http://pyref.infogami.com/reload
What is going on? is this normal behaviour?

yes. and this is tutorial stuff, too:

http://pytut.infogami.com/node8.html

</F>
 
P

Paul McGuire

fileexit said:
Hi,
Shouldn't python recompile a module if there is a later version of the
code (.py file)? While i am debuging, i always have to exit python and
delete the pyc before every run, then start it again and import the
modules. It seems that this is the only way for it to recompile the
new code.

What is going on? is this normal behaviour? I noticed that on both
Windows and linux (Fedora Core 4, and 5 and RHEL 4)
If there is a later .py file, and you restart Python, Python will recompile
the modules when you import them.

-- Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top