How do you develop in Python?

Just van Rossum just at letterror.com
Fri Jun 8 11:00:58 EDT 2001


"Louis M. Pecora" wrote:

> > Just van Rossum wrote:
> >
> > > It's simple: if you modify B.py, _run_ B.py to refresh it (*). A.py will see
> > > the changes. It's hardly ever neccesary to quit the MacPython IDE.
> > >
> > > *) In other words: if B.py has already been imported, running it it will
> > > execute it in B's old namespace, effectively refreshing it for everybody
> > > to see.
> >
> > This is a classic, why didn't I think of that? solution. I think I will
> > still use my method for stuff I'm changing a lot, it is less likely that
> > I will forget to do the refresh.
> 
> Just's solution works, but it has the problem that if you change B and
> C and D depend on B and are used in A, then C and D have to be run, too
> before you run A.  I stumbled on that one. 

It depends: this is only true if C and D either derive from classes in B or do
"from B import *". The latter you should avoid anyway, but the former can be
a real pain indeed. *However* there is another little known feature in the
MacPython IDE that can be extremely handy: you can "reload" individual methods.
You do this by selecting the method(s) and choose "Run selection" (or hit enter).
This inserts the updated code into the *existing* class object. Beware, though:
methods below the section you changed now have different line numbers, but the
code objects don't know that, so tracebacks might point you to the wrong line.
It's a hack, but I find it extremely useful. Think about it: it even updates
existing *instances* as it updates a class in place! It's hacking on live
objects...

Just



More information about the Python-list mailing list