[Tutor] debugging a module from a Package with IDLE interpreter

D-Man dsh8290@rit.edu
Tue, 3 Apr 2001 15:25:26 -0400


On Tue, Apr 03, 2001 at 02:40:29PM -0400, Benoit Dupire wrote:
| I am trying to debug a python program with IDLE... it's really a pain in
| the neck..
| Here is an example... i want to load src.chasm.loader (.py) to debug it.
| 
| Python 2.0 (#8, Oct 16 2000, 17:27:58) [MSC 32 bit (Intel)] on win32
| Type "copyright", "credits" or "license" for more information.
| IDLE 0.6 -- press F1 for help
| 
| >>> import src.chasm.loader
| Traceback (innermost last):  <SNIP!>
| ImportError: No module named setNavBehavior.py
| 
| ### <<< A bug was found >>> ###
| ### <<< i fix the bug in my editor  >>>####
| ### << I want to (re) load src.chasm.loader to find the next bug>> ###
| 

...

| Do i miss something ?

Yes <wink>.  CPython tries to be smart (err, fast at least) -- when
you import a module, it cahces it.  The next time you import it it
simply gives you a reference.  It doesn't read the file from disk
again.  Use the reload() function to force the interpreter to read the
module from disk again.  (I've heard that it doesn't work quite right
in PythonWin or Idle or some IDE, but I don't remember which)

>>> print reload.__doc__
reload(module) -> module

Reload the module.  The module must have been successfully imported
before.
>>>


Hmm,  it must have been successfully imported before.  I suppose the
following might work in your situation :

import src
import sys.chasm.loader
... errors, fix bug
reload( src )
import src.chasm.loader



HTH,
-D