How do I do this without class methods ?
aleaxit at yahoo.com
Wed May 2 12:23:22 EDT 2001
"Jacek Generowicz" <jmg at ecs.soton.ac.uk> wrote in message
news:g0itjjrb6z.fsf at scumbag.ecs.soton.ac.uk...
> OK, I've found an interesting solution to the problem: Alex'
> static-methods recipe . . . but it does seem to mess up inheritance
> somewhat, by having to replace self._class__.unit_area with the more
> explicit and specific polygon.unit_area in polygon.set_class_cache.
> Is there a way of improving on this ?
Depends on what you consider an improvement. You do have to
pass the class-object *somewhere*, either implicitly or explicitly.
> def set_class_cache ( N ):
You may change this to:
def set_class_cache(klass, N):
> # The next line had to be changed
> # self.__class__.unit_area = N * math.sin( 2 * math.pi / N )
> polygon.unit_area = N * math.sin( 2 * math.pi / N )
and therefore this to
klass.unit_area = whatever
so it becomes perfectly-inheritable,
> def set_parameter_ideal ( klass, N ):
> klass.set_class_cache( N )
And this call to
More information about the Python-list