IDLE confusion

taleinat at gmail.com taleinat at gmail.com
Wed May 17 07:47:45 EDT 2006


This isn't really an IDLE issue, it's a Python feature which needs to
be understood.

In Python, once you've imported a module once, importing it again is
ignored. This works fine under the assumption that modules don't change
during a single Python session. However, when you're developing a
module this isn't true, and a workaround for this mechanism is needed.


The safest way to go is to start a new Python session.

In the IDLE interpreter ("Shell" window) you can do this from the Shell
menu. Running a module from an IDLE editor window (Run->Run Module)
will also restart the interpreter.

Notice, however, that these will only work if IDLE has a sub-process
for the interpreter! If not, the Shell menu won't exist, and Run Module
won't restart the interpreter.

On Windows, opening IDLE by right-clicking a file and choosing 'Edit
with IDLE' will cause it to open without a subprocess.



If you change a module and want to use the newer version in the same
Python session, use the built-in 'reload' function:

import Test
reload(Test)

Notice that if you use the 'from <module> import ...' syntax, you need
to import the module itself (i.e. import <module>) before you can
reload it.

I advise to use this with care, as things can get quite confusing after
a few reloads...




More information about the Python-list mailing list