...

/

Using Classes Instead of Closures

Using Classes Instead of Closures

Take a look at a scenario in which the use of classes is preferred over the use of closures in order to allow for more complex initialization requirements.

Callable class instance

While we are looking at classes, it is worth mentioning that you can create classes that can be “called” like functions. All we need to do is to define a method, __call__, in the class. This is useful to know but probably not something you will use often.

__call__ is one of the special methods that Python provides to allow user-defined objects to support Python operators. All the methods have ...