Re-loading updated modules

Discussion in 'Python' started by fileexit, Jun 27, 2006.

  1. fileexit

    fileexit Guest

    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)
     
    fileexit, Jun 27, 2006
    #1
    1. Advertising

  2. 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
     
    Pierre Quentel, Jun 27, 2006
    #2
    1. Advertising

  3. "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>
     
    Fredrik Lundh, Jun 27, 2006
    #3
  4. fileexit

    Paul McGuire Guest

    "fileexit" <> wrote in message
    news:...
    > 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
     
    Paul McGuire, Jun 27, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Remy Cool
    Replies:
    1
    Views:
    433
    Remy Cool
    Aug 27, 2003
  2. aurora
    Replies:
    2
    Views:
    289
    Bryan
    Oct 16, 2004
  3. Guest
    Replies:
    2
    Views:
    266
    Lee Harr
    Oct 15, 2004
  4. Replies:
    2
    Views:
    292
  5. Dmitry Korolyov

    Datagrid not updated during delete, but updated during insert and update

    Dmitry Korolyov, Sep 22, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    420
    Dmitry Korolyov
    Sep 22, 2003
Loading...

Share This Page