Perl/Python/Ruby common backend (Parrot, can Ruby play too?)
dalke at acm.org
Tue Aug 7 17:10:40 CEST 2001
[c.l.ruby removed, for obvious reasons]
Alex Martelli wrote:
>If you want existing instances to NOT be changed, in Python,
>just leave the existing class object alone and build a new one.
Right, but she wanted a way to update existing class
definitions *and* existing instances.
>class theclass(theclass): pass
Cute :) but it doesn't update existing instances.
def eat(self): print "yum"
spam = Spam()
# Oops, I don't like spam, so let me change that
... code to update Spam, as perhaps
def Spam.eat(self): print "yech"
# Uses the old 'spam'
This should print
and using a 'class Spam(Spam): def eat(self): print "yech"'
is not enough.
BTW, I wish to stress that I am not pushing this to be added to
Python. I am not sure enough about the use case on what this
is based to tell if this is a useful solution. (Eg, it could
be that reloading a module in a way that changes class definitions
in-place rather than replacing them is more appropriate.)
Still, I know in interactive mode that I've made a lot of
mistakes in making a class, so perhaps something like this
would be useful. (Given the chance for abuse, I don't think
it is useful.)
dalke at dalkescientific.com
More information about the Python-list