Message410137
The safe way of using read_lines() is:
lines = read_lines()
try:
# use lines
finally:
lines.close()
or
with contextlib.closing(read_lines()) as lines:
# use lines
And it is in no way better than using "with open()" directly.
I think it is better to not add such sing to the stdlib because it only makes an illusion of safety but actually removes safety guards.
If we want using generators in expressions we need to add support for "with" in expressions and comprehensions.
data = json.load(f) with open(path, 'rb') as f
lines = (line.strip() for path in files with open(path) as f for line in f) |
|
Date |
User |
Action |
Args |
2022-01-09 10:57:23 | serhiy.storchaka | set | recipients:
+ serhiy.storchaka, jaraco, eric.smith, njs, Dennis Sweeney |
2022-01-09 10:57:23 | serhiy.storchaka | set | messageid: <1641725843.81.0.678904281735.issue46304@roundup.psfhosted.org> |
2022-01-09 10:57:23 | serhiy.storchaka | link | issue46304 messages |
2022-01-09 10:57:23 | serhiy.storchaka | create | |
|