Test of comp.lang.python to python-list to gmane pathway.

Terry Reedy tjreedy at udel.edu
Sun Jan 30 03:37:08 EST 2005


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" <tjreedy at udel.edu> wrote in message 
news:cthdth$fp0$1 at sea.gmane.org...
>
> "Michael Tobis" <mt at 3planes.com> wrote in message 
> news:1107040729.535936.42230 at c13g2000cwb.googlegroups.com...
>
>> 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
> 





More information about the Python-list mailing list