[Tutor] reloading all modules?

Don Arnold Don Arnold" <darnold02@sprynet.com
Tue Apr 29 22:58:01 2003

----- Original Message -----
From: "Magnus Lyckå" <magnus@thinkware.se>
To: "Zak Arntson" <zak@harlekin-maus.com>; <tutor@python.org>
Sent: Tuesday, April 29, 2003 9:28 PM
Subject: Re: [Tutor] reloading all modules?

> At 18:09 2003-04-29 -0700, Zak Arntson wrote:
> >I'm working on a project in IDLE, and I often modify several modules at
> >once. When I change a module, I've got to save it and reload () it. This
> >can be a pain with reloading 3 modules every time I want to rerun my
> >program!
> >
> >Is there a way to reload all imported modules in memory? Or del them all?
> In IDLE? Don't think so...
> My suggestion is to just edit filed in IDLE (or PythonWin or
> whatever) and then run them from the command line. Then you
> get a fresh start every time, and your running program isn't
> "disturbed" by all the modules in IDLE etc. Printing will be
> much faster, there are no problem with GUI event loops messing
> things up for each other--as well as the load problem.
> I guess using an IDE which always run the code in a separate
> process helps. Try IDLE-fork for the most convenient way to
> get that feature.
> --
> Magnus Lycka (It's really Lyck&aring;), magnus@thinkware.se
> Thinkware AB, Sweden, www.thinkware.se
> I code Python ~ The shortest path from thought to working program

What I've done before instead of using a plain vanilla import in my modules
is wrapping the reload in a try block and importing on the exception:

except NameError:
    import mymodule

Of course, if you're working directly from the interpreter prompt, it's
admittedly not too useful.