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 eric.smith
Recipients benjamin.peterson, berker.peksag, eric.smith, mjpieters, python-dev, r.david.murray, vajrasky, vstinner
Date 2015-01-05.08:29:14
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1420446554.47.0.616933655714.issue18644@psf.upfronthosting.co.za>
In-reply-to
Content
Not that I think it's worth changing for this case, but I find code like this better written as:

if some_test:
    fl = contextlib.closing(open(sys.argv[1]))
else:
    fl = sys.stdin
with fl as fl:
    do_stuff(fl)

This way you don't need another test, the close isn't far away from the open, and you save some lines of boilerplate.


Or, if "with fl as fl" bothers you:

with sys.stdout if some_test else contextlib.closing(open(sys.argv[1])) as fl:
    do_stuff(fl)

I don't recommend that, though.

In any event, thanks for the fix!
History
Date User Action Args
2015-01-05 08:29:14eric.smithsetrecipients: + eric.smith, mjpieters, vstinner, benjamin.peterson, r.david.murray, python-dev, berker.peksag, vajrasky
2015-01-05 08:29:14eric.smithsetmessageid: <1420446554.47.0.616933655714.issue18644@psf.upfronthosting.co.za>
2015-01-05 08:29:14eric.smithlinkissue18644 messages
2015-01-05 08:29:14eric.smithcreate