Develop-test-debug cycle

logistix logstx at bellatlantic.net
Wed Mar 20 18:08:33 EST 2002


Like Tim said, the module is getting reloaded but instances aren't getting
re-instantiated.  If it's not too time-intensive, use the if
__name__=="__main__" trick in your script.

if __name__ == "__main__":
    reload(wibbleModule)
    wibs = wibble(args)
    wibs.test1()
    wibs.test2()

and just run it again from the interpreter.

If that's too slow and you want to use some really bad voodoo, you can also
modify the classes in-place:

PythonWin 2.2 (#28, Dec 21 2001, 12:21:22) [MSC 32 bit (Intel)] on win32.
Portions Copyright 1994-2001 Mark Hammond (mhammond at skippinet.com.au) - see
'Help/About PythonWin' for further copyright information.
>>> class foo:
...  def meth(self):
...   print "xxx"
...
>>> bar = foo()
>>> bar.meth()
xxx
>>> def newMeth(self):
...  print "yyy"
...
>>> foo.meth = newMeth
>>> bar.meth()
yyy


--
-

"Dale Strickland-Clark" <dale at riverhall.NOTHANKS.co.uk> wrote in message
news:un2h9ukh13kddcd3ooc9osejapiaf5v6t3 at 4ax.com...
> I can't believe I'm doing this this best way.
>
> I am debugging a large system written in Python with modules spread
> over 4 directories. I'm using PythonWin under Win2K to set-up the
> environment and run the code.
>
> Setting up the environment typically involves the following commands:
>
> import sys
> sys.path.append("x:\\whereever")
> from wibbleModule import wibble
> wibs = wibble(args)
>
> wibs.methods(args)
>
> <error...>
>
> At this point, I fix the error.
>
> Now, I haven't figured out a way of continueing past this point
> without quiting and starting from scratch because there appears to be
> no way to get Python to reload a module. The reload() function doesn't
> do it.
>
> I've tried stuff like this:
>
> del wibs
> reload(sys.modules['wibbleModule']
>
> but I still seem to have the old version loaded.
>
> I've also tried using PyCrust for this but it suffers from the same
> problems. I assume IDLE does too.
>
> How do others go about interactively debugging large Python OO-based
> systems?
>
> Thanks for any pointers.
> --
> Dale Strickland-Clark
> Riverhall Systems Ltd





More information about the Python-list mailing list