FAQ
I'm using the Windows version of Python and IDLE. When I debug my .py
file, my modification to the .py file does not seem to take effect
unless I restart IDLE. Saving the file and re-importing it doesn't help

either. Where's the problem?

Thanks.

Search Discussions

  • Jeremy Jones at Dec 2, 2005 at 2:27 pm

    sandorf wrote:
    I'm using the Windows version of Python and IDLE. When I debug my .py
    file, my modification to the .py file does not seem to take effect
    unless I restart IDLE. Saving the file and re-importing it doesn't help

    either. Where's the problem?

    Thanks.

    No problem. Just reload() it.


    - jmj
  • Infidel at Dec 2, 2005 at 4:56 pm

    I'm using the Windows version of Python and IDLE. When I debug my .py
    file, my modification to the .py file does not seem to take effect
    unless I restart IDLE. Saving the file and re-importing it doesn't help
    either. Where's the problem?
    "import" only reads the file the first time it's called. Every import
    call after that looks up the module in memory. This is to prevent
    circular dependencies between modules from creating infinite loops.
    You need to use the reload() function:
    import foo
    #change the contents of foo
    foo = reload(foo)
  • Christophe at Dec 2, 2005 at 5:04 pm

    infidel a ?crit :
    I'm using the Windows version of Python and IDLE. When I debug my .py
    file, my modification to the .py file does not seem to take effect
    unless I restart IDLE. Saving the file and re-importing it doesn't help
    either. Where's the problem?

    "import" only reads the file the first time it's called. Every import
    call after that looks up the module in memory. This is to prevent
    circular dependencies between modules from creating infinite loops.
    You need to use the reload() function:
    As a matter of fact, it would help a lot if that stupid behaviour of
    Idle was dropped. I'm sure I'm not the only one who lost lots of time
    because of that bug. Yes I call it a bug.
  • Scott David Daniels at Dec 3, 2005 at 5:07 am

    Christophe wrote:
    infidel a ?crit :
    I'm using the Windows version of Python and IDLE. When I debug my .py
    file, my modification to the .py file does not seem to take effect
    unless I restart IDLE. Saving the file and re-importing it doesn't help
    either. Where's the problem?
    "import" only reads the file the first time it's called. Every import
    call after that looks up the module in memory. This is to prevent
    circular dependencies between modules from creating infinite loops.
    You need to use the reload() function:
    As a matter of fact, it would help a lot if that stupid behaviour of
    Idle was dropped. I'm sure I'm not the only one who lost lots of time
    because of that bug. Yes I call it a bug.
    You are mistaken if you think this is an Idle behavior; it is a Python
    behavior that speeds the execution of large systems.

    --Scott David Daniels
    scott.daniels at acm.org
  • Fredrik Lundh at Dec 3, 2005 at 7:33 am

    Christophe wrote:

    "import" only reads the file the first time it's called. Every import
    call after that looks up the module in memory. This is to prevent
    circular dependencies between modules from creating infinite loops.
    You need to use the reload() function:
    As a matter of fact, it would help a lot if that stupid behaviour of
    Idle was dropped. I'm sure I'm not the only one who lost lots of time
    because of that bug. Yes I call it a bug.
    in the version of IDLE I have on this machine, if I modify my script and
    run it again (using F5), things work exactly as expected.

    if I modify my script and import it into a clean shell (ctrl-F6), things work
    exactly as expected.

    the only way to get the "buggy" behaviour you're describing is to attempt
    to run your program by importing it as a module more than once into an
    existing python shell process. in that case, import works in the same way
    as it always works.

    after all, "import" isn't designed to run programs, it's designed to import
    modules. if you want to run stuff in IDLE, why not just use the "run"
    command ?

    </F>
  • Christophe at Dec 5, 2005 at 1:33 pm

    Fredrik Lundh a ?crit :
    Christophe wrote:

    "import" only reads the file the first time it's called. Every import
    call after that looks up the module in memory. This is to prevent
    circular dependencies between modules from creating infinite loops.
    You need to use the reload() function:
    As a matter of fact, it would help a lot if that stupid behaviour of
    Idle was dropped. I'm sure I'm not the only one who lost lots of time
    because of that bug. Yes I call it a bug.

    in the version of IDLE I have on this machine, if I modify my script and
    run it again (using F5), things work exactly as expected.

    if I modify my script and import it into a clean shell (ctrl-F6), things work
    exactly as expected.

    the only way to get the "buggy" behaviour you're describing is to attempt
    to run your program by importing it as a module more than once into an
    existing python shell process. in that case, import works in the same way
    as it always works.

    after all, "import" isn't designed to run programs, it's designed to import
    modules. if you want to run stuff in IDLE, why not just use the "run"
    command ?
    F5 is designed to run the current open file. Sane people won't assume
    that pressing twice the F5 key will yield different. Sane people will
    assume that when you edit file1.py and press F5, it reparses the file,
    but when you edit file2.py and press F5 with file1.py it won't work. Why
    make it different ? Why make is so that I have to select the shell
    window, press CTRL+F6, select the file1.py and press F5 just so that it
    works as expected ?

    Idle is ok when you edit a single .py file. As soon as I need to edit 2
    .py files with one using the other, I'm glad I have other editors which
    spanw a clean shell each time I run the current file.
  • Fredrik Lundh at Dec 5, 2005 at 1:58 pm

    "Christophe" wrote:

    F5 is designed to run the current open file. Sane people won't assume
    that pressing twice the F5 key will yield different. Sane people will
    assume that when you edit file1.py and press F5, it reparses the file,
    but when you edit file2.py and press F5 with file1.py it won't work. Why
    make it different ? Why make is so that I have to select the shell
    window, press CTRL+F6, select the file1.py and press F5 just so that it
    works as expected ?
    I'm not sure I follow here: in the version of IDLE I have here, pressing
    F5 will save the current file and run it. If you've edit other parts of the
    application, you have to save those files (Control-S) and switch to the
    main script before pressing F5, but that's only what you'd expect from
    a "run this module" command.

    (being able to bind F5 to a specific script might be practical, of course,
    but I'm don't think that's what you're complaining about. or is it?)
    Idle is ok when you edit a single .py file. As soon as I need to edit 2
    .py files with one using the other, I'm glad I have other editors which
    spanw a clean shell each time I run the current file.
    In the version of IDLE I have, that's exactly what happens (that's what
    the RESTART lines are all about).

    Is there some secret setting somewhere that I've accidentally managed
    to switch on or off to get this behaviour?

    </F>
  • Christophe at Dec 5, 2005 at 3:15 pm

    Fredrik Lundh a ?crit :
    "Christophe" wrote:

    F5 is designed to run the current open file. Sane people won't assume
    that pressing twice the F5 key will yield different. Sane people will
    assume that when you edit file1.py and press F5, it reparses the file,
    but when you edit file2.py and press F5 with file1.py it won't work. Why
    make it different ? Why make is so that I have to select the shell
    window, press CTRL+F6, select the file1.py and press F5 just so that it
    works as expected ?

    I'm not sure I follow here: in the version of IDLE I have here, pressing
    F5 will save the current file and run it. If you've edit other parts of the
    application, you have to save those files (Control-S) and switch to the
    main script before pressing F5, but that's only what you'd expect from
    a "run this module" command.

    (being able to bind F5 to a specific script might be practical, of course,
    but I'm don't think that's what you're complaining about. or is it?)

    Idle is ok when you edit a single .py file. As soon as I need to edit 2
    .py files with one using the other, I'm glad I have other editors which
    spanw a clean shell each time I run the current file.

    In the version of IDLE I have, that's exactly what happens (that's what
    the RESTART lines are all about).

    Is there some secret setting somewhere that I've accidentally managed
    to switch on or off to get this behaviour?
    What I remember ( but maybe it was changed in recent Idle versions ) was
    that when your project has a main.py which imports a module.py, when you
    run your project once, any later changes you make in module.py won't be
    taken into account.
  • Dave Hansen at Dec 5, 2005 at 3:54 pm

    On Fri, 02 Dec 2005 18:04:15 +0100 in comp.lang.python, Christophe wrote:

    infidel a ?crit :
    I'm using the Windows version of Python and IDLE. When I debug my .py
    file, my modification to the .py file does not seem to take effect
    unless I restart IDLE. Saving the file and re-importing it doesn't help
    either. Where's the problem?

    "import" only reads the file the first time it's called. Every import
    call after that looks up the module in memory. This is to prevent
    circular dependencies between modules from creating infinite loops.
    You need to use the reload() function:
    As a matter of fact, it would help a lot if that stupid behaviour of
    Idle was dropped. I'm sure I'm not the only one who lost lots of time
    because of that bug. Yes I call it a bug.
    But, if you are editing a Python Module in Idle, and press F5 to run
    the module, the interpreter is restarted for you. So what's the
    problem?

    I would consider it a far greater problem if Idle _didn't_ do that --
    it could mean you module worked when you were debuggining it because
    of some initialization that doesn't get performed in a clean start.

    Regards,
    -=Dave

    --
    Change is inevitable, progress is not.
  • Christophe at Dec 5, 2005 at 4:09 pm

    Dave Hansen a ?crit :
    On Fri, 02 Dec 2005 18:04:15 +0100 in comp.lang.python, Christophe
    wrote:

    infidel a ?crit :
    I'm using the Windows version of Python and IDLE. When I debug my .py
    file, my modification to the .py file does not seem to take effect
    unless I restart IDLE. Saving the file and re-importing it doesn't help
    either. Where's the problem?

    "import" only reads the file the first time it's called. Every import
    call after that looks up the module in memory. This is to prevent
    circular dependencies between modules from creating infinite loops.
    You need to use the reload() function:
    As a matter of fact, it would help a lot if that stupid behaviour of
    Idle was dropped. I'm sure I'm not the only one who lost lots of time
    because of that bug. Yes I call it a bug.

    But, if you are editing a Python Module in Idle, and press F5 to run
    the module, the interpreter is restarted for you. So what's the
    problem?

    I would consider it a far greater problem if Idle _didn't_ do that --
    it could mean you module worked when you were debuggining it because
    of some initialization that doesn't get performed in a clean start.

    Regards,
    -=Dave
    Well, I'm happy to see that Idle now restarts the interpreter by default
    when you press F5. I guess I might consider using it again after all
    that time :)

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedDec 2, '05 at 2:16p
activeDec 5, '05 at 4:09p
posts11
users7
websitepython.org

People

Translate

site design / logo © 2022 Grokbase