Please re-write examples to use `with ... as request:` style
Closed this issue · 2 comments
jepler commented
The examples, at least simpletest, use code structured like this:
print("Fetching text from %s" % TEXT_URL)
response = requests.get(TEXT_URL)
print("-" * 40)
print("Text Response: ", response.text)
print("-" * 40)
response.close()
In modern Python, using a with
statement is idomatic and provides the best resource management, because the need to manually call close (including in exception cases) is removed:
print("Fetching text from %s" % TEXT_URL)
with requests.get(TEXT_URL) as response:
print("-" * 40)
print("Text Response: ", response.text)
print("-" * 40)
jepler commented
@justmobilize thanks!
justmobilize commented
@jepler you are quite welcome