Function Interfaces and Callback-Based Code : Interface « Class « Python Tutorial






class Callback:
    def __init__(self, color):            
        self.color = color
    def __call__(self):                   
        print 'turn', self.color

cb1 = Callback('blue')                    
cb2 = Callback('green')

cb1(  )                                   
cb2(  )                                   


cb3 = (lambda color='red': 'turn ' + color) 
print cb3(  )








11.12.Interface
11.12.1.Class Interface Techniques
11.12.2.Function Interfaces and Callback-Based Code