You can write this with one level of indentation:
https://docs.python.org/3/library/contex....ExitStack
By the way, it's good to read the whole document. You'll find functions like suppress, closing. etc.
with requests.Session() as rest_session, open("log.txt", "a") as log: data = rest_session.get_data() unrelated = read(log) write(data, log) if unrelated == "OK": rest_session.POST("spam")Since some Python 3.x version it's possible. Before this was introduced, it was also possible with a helper function from the contextlib.
https://docs.python.org/3/library/contex....ExitStack
By the way, it's good to read the whole document. You'll find functions like suppress, closing. etc.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!