how to call back a method in python3?

Gregory Ewing greg.ewing at canterbury.ac.nz
Mon Aug 4 02:18:33 EDT 2014


Marko Rauhamaa wrote:
> Do this:
> 
>     class MyClass:
>         def my_method(self):
>             def callback(x):
>                 return self.do(x)
>             return callback
> 
>         def do(self, x):
>             print("done: {}".format(x))

Or more simply:

       def my_method(self):
          return self.do

-- 
Greg



More information about the Python-list mailing list