Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re-loading updated modules

Reply
Thread Tools

Re-loading updated modules

 
 
fileexit
Guest
Posts: n/a
 
      06-27-2006
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)

 
Reply With Quote
 
 
 
 
Pierre Quentel
Guest
Posts: n/a
 
      06-27-2006
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

 
Reply With Quote
 
 
 
 
Fredrik Lundh
Guest
Posts: n/a
 
      06-27-2006
"fileexit" <> wrote:

> 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>



 
Reply With Quote
 
Paul McGuire
Guest
Posts: n/a
 
      06-27-2006
"fileexit" <> wrote in message
news: ups.com...
> 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



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: (updated) Choosing a collection of common modules/packages for ageneral purpose reusable PY2EXE runtime python@bdurham.com Python 2 03-20-2010 12:46 PM
reloading updated modules in long running server? aurora Python 2 10-16-2004 03:07 PM
Re: reloading updated modules in long running server? Python 2 10-15-2004 08:08 PM
Datagrid not updated during delete, but updated during insert and update Dmitry Korolyov ASP .Net Datagrid Control 0 09-22-2003 10:57 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57