Feel free to ignore this. Some system falsely labeled this post (sent via gmane) as possible spam. I am sending it back in the opposite direction to see what transpires that way. Sorry for the disturbance. tjr
"Terry Reedy" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > "Michael Tobis" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > >> I'd like to dynamically add a method to an instance at >> instantiation time. > > No can do. A method is function that is an attribute of a class, even if > accessed via an instance. A function added to an instance as an > attribute of the instance remains a function. It is instance-specific > data that methods and other code can use, just like other instance data, > for instance-specific effects. Two common examples: > > class composer: > # skip obvious init > def __call__(self, x): return self.outer(self.inner(x)) > > sincos = composer(math.sin, math.cos) > # yes, this can also be done with composer function with nested scope > > class memoizer: # posted several times > # skip init again > def __call__(self,x): > # return previously computed self.memodict[x] if it exists > # or calculate, store, and return self.func(x) > > \> PS - any idea how to get past google's stupid formatting these days? I >> thought they were supposed to like python, but they just ignore leading >> blanks. > > Don't use google to post on clp. Go to news.gmane.org instead. > > Terry J. Reedy > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list