This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author serhiy.storchaka
Recipients Dennis Sweeney, eric.smith, jaraco, njs, serhiy.storchaka
Date 2022-01-09.10:57:23
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1641725843.81.0.678904281735.issue46304@roundup.psfhosted.org>
In-reply-to
Content
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)
History
Date User Action Args
2022-01-09 10:57:23serhiy.storchakasetrecipients: + serhiy.storchaka, jaraco, eric.smith, njs, Dennis Sweeney
2022-01-09 10:57:23serhiy.storchakasetmessageid: <1641725843.81.0.678904281735.issue46304@roundup.psfhosted.org>
2022-01-09 10:57:23serhiy.storchakalinkissue46304 messages
2022-01-09 10:57:23serhiy.storchakacreate