How to create functors?

Steven D'Aprano steven at
Thu Aug 20 06:11:32 CEST 2009

On Wed, 19 Aug 2009 18:42:32 -0700, Paul Rubin wrote:

> Robert Dailey <rcdailey at> writes:
>> I want to simply wrap a function up into an object so it can be called
>> with no parameters.
> Nitpick: what you are asking for is called a closure.  "Functor" means
> something completely different.

I'm glad somebody else noticed this. I would have said something about it 
myself, except I wasn't entirely sure my understanding of functor is 
correct. As near as I can tell, a functor is just an object which is 
callable like a function without actually being implemented as a 
function, e.g.:

class Functor:
    def __call__(self):
        return None

f = Functor()
result = f()


More information about the Python-list mailing list