Getting a class attribute
Roger Hansen
rogerha at ifi.uio.no
Fri Mar 24 11:35:36 EST 2000
* alex at somewhere.round.here
>
>
> > It is possible to get the class atribute "a" in the default function
> > parameter?
>
> My understanding is that the default values are computed at compile
> time, so not really. Perhaps you could redefine the function each time
> the member 'a' changes? Here is an example. It does not really make
> new_degree_sin4 into a class method, as I don't know how. I am pretty
> sure it's possible and desirable to do so, though. Hopefully someone
> else will tell you.
>
> Come-join-my-cargo-cult'ly yrs
> Alex.
>
> import math
>
> class Eg:
>
> def __init__ (self):
> self.set_factor (1)
>
> def set_factor (self, a):
> self.a = a
> def new_degree_sin4 (deg, factor=(a*(math.pi/180)),
> sin=math.sin):
> return sin (deg * factor)
> self.new_degree_sin4 = new_degree_sin4
Thanks! This solution suits me just fine. And after som testing the
code does infact run much faster.
TTFN
R
More information about the Python-list
mailing list