Perl/Python/Ruby common backend (Parrot, can Ruby play too?)
Andrew Dalke
dalke at acm.org
Tue Aug 7 11:10:40 EDT 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.
>E.g,
>class theclass(theclass): pass
Cute :) but it doesn't update existing instances.
class Spam:
def eat(self): print "yum"
spam = Spam()
spam.eat()
# 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'
spam.eat()
This should print
yum
yech
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.)
Andrew
dalke at dalkescientific.com
More information about the Python-list
mailing list