[Tutor] Is Python really dynamic ?

Daniel Yoo dyoo@hkn.eecs.berkeley.edu
Sat, 24 Mar 2001 10:16:05 -0800 (PST)


On Sat, 24 Mar 2001, Benoit Dupire wrote:

> Why does this still work ? setheading does not exist anymore.... I had
> no clue... until i run this from the command line, where i got the
> correct results, and not from IDLE.

> Could someone explain me why IDLE is messing everything up ?

You're not going to like this:  According to the reference documentation:

"When a module is reloaded, its dictionary (containing the module's global
variables) is retained.  Redefinition of names will override the old
definitions, so this is generally not a problem.  If the new version of a
module does not define a name that was defined by the old version, the old
definition remains."

This comes from:

    http://python.org/doc/current/lib/built-in-funcs.html

So that's why: setheading persists in the module definition if it hasn't
been overridden, so erasing it won't take affect until we restart Python.  
This explains the weirdness that was happening before.  Try writing your
code to change the behavior of setheading, instead of removing it
entirely.

I wonder if there's a way of "clearing" out a module's definition, by
calling "del" on its dictionary of methods.  At the moment, I don't have
easy access to a Python interpreter (the horror!  the horror!), so I can't
confirm this yet.

Hope this helps!