[Tutor] reloading all modules?

Bob Gailer bgailer@alum.rpi.edu
Wed Apr 30 06:01:02 2003


--=======25EC4A41=======
Content-Type: text/plain; x-avg-checked=avg-ok-497732D7; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 8bit

At 06:09 PM 4/29/2003 -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?

2 ideas:
import sys
for module in sys.modules.values():
   try:reload(module)
   except:pass
I use PythonWin. There are a lot of PythonWin-related things in 
sys.modules, and at least one of them won't reload; that's the reason for 
the try.

1st improvement: keep a list of the modules you want to reload and iterate 
over that list instead on sys.modules.

2nd idea:
I wrote a module manager that makes certain checks to see if a reload is 
needed; my main program uses the module manager to import/reload as needed 
and to run the module's code. If interested let me know.

Bob Gailer
bgailer@alum.rpi.edu
303 442 2625

--=======25EC4A41=======
Content-Type: text/plain; charset=us-ascii; x-avg=cert; x-avg-checked=avg-ok-497732D7
Content-Disposition: inline


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.474 / Virus Database: 272 - Release Date: 4/18/2003

--=======25EC4A41=======--