June 2017
Beginner to intermediate
274 pages
6h 49m
English
The following is an example in which we create a specialized version of a dictionary, which could serve as a context manager:

Within the scope of the with block, we can read and write data through the object that we returned from __enter__, but these changes will only be applied to the main dictionary. If the block exits without raising an exception, the return value of the inner method will be used by the with statement for the value to be assigned through the as clause.
Refer to the following code example, the variable trans contains the ChainMap instance. ChainMap objects are dictionaries that ...
Read now
Unlock full access