Can't define __call__ within __init__?

Neal Becker ndbecker2 at
Wed Mar 10 14:12:14 CET 2010

Want to switch __call__ behavior.  Why doesn't this work?  What is the 
correct way to write this?

class X (object):
    def __init__(self, i):
        if i == 0:
            def __call__ (self):
                return 0
            def __call_ (self):
                return 1

x = X(0)

TypeError: 'X' object is not callable

More information about the Python-list mailing list