function factory question: embed current values of object attributes

Alan Isaac aisaac at american.edu
Fri Feb 20 19:49:21 CET 2009


I have a class `X` where many parameters are set
at instance initialization.  The parameter values
of an instance `x` generally remain unchanged,
but is there way to communicate to a method that
it depends only on the initial values of these parameters
(and does not need to worry about any changes)?

The behavior of method `m` depends on these parameter values.
It turns out `m` gets called a lot, which means
that the pameter values are accessed over and over
(self.p0, self.p1, etc).  I would like to
manufacture a function equivalent to the method
that simply uses fixed values (the values at the
time it is manufactured).  I do not care if this
function is attached to `x` or not.

I have a feeling that I am turning something simple
into something complex, perhaps for lack of an
afternoon coffee or lack of CS training.  Suggestions
appreciated.

Alan Isaac



More information about the Python-list mailing list