Do I have to quit python to load a module?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • wang frank

    #1

    Do I have to quit python to load a module?

    Hi,

    When I edit a module, I have to quit python and then restart python and
    then import the module. Are there any way to avoid quit python to load an
    updated module? When I am debugging a module code, I need to constantly
    make changes. It is not convenient to quit and reload.

    Thanks

    Frank

    _______________ _______________ _______________ _______________ _____
    $B%a%C%;%s%8%c !<$*M'C#>R2p%W% l%<%s%HBh(B2$ BCF3+;O!*%i%9%Y %,%9N99T%W%l%<% s%H(B


  • Peter Otten

    #2
    Re: Do I have to quit python to load a module?

    wang frank wrote:
    When I edit a module, I have to quit python and then restart python and
    then import the module. Are there any way to avoid quit python to load an
    updated module? When I am debugging a module code, I need to constantly
    make changes. It is not convenient to quit and reload.
    There is the reload() function, but it has pitfalls. Objects referenced from
    without the module are not updated:
    >>open("tmp.py" , "w").write( """
    .... def f(): print "version one"
    .... """)
    >>import tmp
    >>tmp.f()
    version one
    >>g = tmp.f
    >>open("tmp.py" , "w").write( """
    .... def f(): print "version two"
    .... """)
    >>reload(tmp)
    <module 'tmp' from 'tmp.py'>
    >>tmp.f()
    version two
    >>g()
    version one

    Peter

    Comment

    Working...