overload operator()?

John Hunter jdhunter at ace.bsd.uchicago.edu
Mon Dec 16 15:13:10 EST 2002


>>>>> "Bruce" == Bruce Dickey <brucedickey at micron.com> writes:

    Bruce> Is there a way to overload () in Python to call a
    Bruce> user-defined function?  I've overloaded + | ~ etc, but ()
    Bruce> has me stumped.


See  http://www.python.org/doc/current/ref/specialnames.html

class callme:

    def __call__(self):
        print 'hi'

f = callme()
f()


John Hunter




More information about the Python-list mailing list