Python Notes: Context management

Python supports context management. Which often used when handling resources, for example, file, network connection. With statement helps make sure the resources are cleaned up or released. There are two major functions for context management: __enter__ and __exit__....

Python Notes: Closure

The following is an example of python closure. def outer_function(outter_arg): closure_var = outter_arg def inner_function(inner_arg): print(“{} {}”.format(closure_var, inner_arg)) return inner_function # Usage of a python closure closure_func =...