Getting a class attribute

Alex alex at somewhere.round.here
Fri Mar 24 16:05:31 EST 2000


> That lets you get access to "self", but at the cost of rewriting the
> class method itself.

Ouch, yeah that could be bad.  It would be nice if you could make a new
version of the class, something like this:

new_class = copy.copy (self.__class__)
def new_degree_sin4 (self, deg, factor=(a*(math.pi/180)),
                     sin=math.sin):
    return sin (deg * factor)
new_class.new_degree_sin4 = new_degree_sin4
self.__class__ = new_class

but it seems that classes aren't copy'able.  Plus, this has other
problems with class members that you actually would like to be
accessible to all instances.  Oh, well.

Alex.



More information about the Python-list mailing list