June 2019
Beginner to intermediate
770 pages
19h 24m
English
In a way, the presence of nested contexts means that top-level scripts ought to look like the following code:
if __name__ == "__main__":
with Setup_Logging(): with Build_Config(arguments) as config_3: simulate_blackjack_betting(config_3)
We've added two context managers to formalize the creation of the working context. For more information, see Chapter 6, Using Callables and Contexts. Here is a context manager for logging:
class Setup_Logging: def __enter__(self, filename="logging.config") -> "Setup_Logging":
logging.config.dictConfig(yaml.load(filename))
def __exit__(self, *exc) -> None:
logging.shutdown()
The idea is to be sure that the logging process is properly configured and shut down when the ...
Read now
Unlock full access