Eric V. Smith added the comment:

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!

----------
nosy: +eric.smith

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue18644>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to