Calling a class instance like a function

Uberman bhood37 at hotmail.com
Wed Feb 18 20:32:11 EST 2009


Thank you very much, Filip!!  :)

Filip Gruszczyński wrote:
> __call__
> 
> 2009/2/19 Uberman <bhood37 at hotmail.com>:
>> I'm wondering if there's a way to invoke a "function" operator on a Python
>> class instance.  For example, given a class instance:
>>
>>        myClass = MyClass()
>>
>> I want to call that instance like a function, with an argument value:
>>
>>        myClass(5.0)
>>
>> I can override the "()" operator in C++, so I'm wondering if there's a way to
>> do it in Python as well.
>>
>> Thanks!
>> --
>> http://mail.python.org/mailman/listinfo/python-list



More information about the Python-list mailing list