IsPython really O-O?
sholden at holdenweb.com
Thu Nov 15 00:17:21 CET 2001
"Andrew Dalke" <dalke at dalkescientific.com> wrote .
> >>I wanted to add a new method, so I did
> >>class Spam:
> >> def double(self):
> >> self.x = self.x * 2
> Daniel Klein:
> >Just curious to know how it is that you expected this to work
> Because I didn't think that 'class Spam' always created a new
> class. I thought it would reuse a definition of one already exists.
> I believe this is similar to what Smalltalk does.
> > why you were 'annoyed'?
> Because it didn't fit my model of how the language worked, so
> was more effort to learn.
> >I can't
> >see what the problem is with the double() method.
> The problem was I wanted to add a method to an existing class.
> The method definition was fine.
ISTR someone suggested some time ago that we might use
self.x *= 2
to add or redefine methods, but I don't remember why this was thought to be
a bad idea. I suppose in all such cases it's bad that there's no way to
reach out to existing instances and modify them. SmallTalk's introspection
system has it over Python in that respect, but then (like me :) it's more
memory's-not-what-it-was-ly y'rs - steve
More information about the Python-list