interactive shell -- reload definitions?

Jack Diederich jack at performancedrivers.com
Wed May 10 13:46:01 EDT 2006


On Wed, May 10, 2006 at 10:00:38AM -0700, malv wrote:
> This is a question that comes up almost continuously for at least six
> years now.
> For Python users having to deal with major real-life applications, this
> may make them think twice about the future suitability of Python as a
> competitive development tool.
> Ruby is featuring a software modify and go feature. Lisp is, even VB
> does. In the design of Smalltalk this used to be one of the major
> considerations.
> 
> Plenty of posts will turn up doing a search on "reload". The following
> references summarize some of these problems:
> http://groups.google.com/group/comp.lang.python/browse_frm/thread/efba62d227ba4794/41f57f366affd057?q=Hung+Jung+Lu+reload&rnum=2#41f57f366affd057
> http://groups.google.com/group/comp.lang.python/browse_frm/thread/efba62d227ba4794/41f57f366affd057?q=Hung+Jung+Lu+reload&rnum=2#41f57f366affd057
> 
> In fact, doing a reload usually will not accomplish what one is looking
> for. Class instances should also be upgraded on reload(), preferably
> automatically. This can be accomplished as shown by Michael Hudson in:
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/160164
> Variants on this theme exist which seem to be broken.

reload() cannot always do exactly what you want it to do because what
you want it to do isn't always the same.  Upgrading instances to the
new definition of the class may be handy sometimes but what is the
'right' thing to do here?

# test.py version 1
class A:
  def __init__(self, val):
    self.hello_wolrd = val
  def __str__(self):
    return self.hello_world

# test.py version 2
class A:
  def __init__(self, val):
    self.himom = val
  def __str__(self):
    return self.himom

reload() can never know that 'hello_world' was renamed to 'himom'
so if you upgrade the class of existing instances str(ob) will explode.
reload() is only handy for interactive use.  If you try to use it in any
non-trivial production program you will get burned.  It can never be
made magic enough.

> Given the persistent push of Ruby, I would strongly recommend that a
> workable integrated solution will be found for Reload & Go in Python,
> taking priority on many way out features of rather low practicality for
> many  programmers.

Link?  Google finds lots of unrelated stuff because reload is a common
word.  

-Jack



More information about the Python-list mailing list