troy at gci.net
Wed Jul 2 03:46:28 CEST 2003
Tom Plunket wrote:
> What I want (being a C++ coder <g>), is to be able to create an
> object that I is callable.
I'm not quite certain how you intend to use the classes you provided in your
original post, but the answer to your question is to define a __call__
method in your class. Untested example:
def __init__(self, factor):
self.factor = factor
def __call__(self, value):
return value * self.factor
my_object = SomeClass(3)
You can learn more about __call__ and other special functions for classes in
the Language Reference (section 3.3 for python2.2).
More information about the Python-list