[Python-ideas] Boolean value of file object?
solipsis at pitrou.net
Sun Jan 8 02:20:32 CET 2012
On Sat, 7 Jan 2012 17:07:13 -0800
Mike Meyer <mwm at mired.org> wrote:
> Just an off-the-wall thought.
> Is there any reason a file object's boolean value shouldn't be false
> once it's been closed? This would allow replacing "if f and f.closed:" (to
> make sure you have a file and it's open) with just "if f:". Is there
> some use case where you want to verify that an object is a file
> object instead of None (or another false value), and don't care if
> it's closed?
That sounds just too smart. It is not obvious that a file should become
"false" once it is closed. Writing "f.closed" OTOH is explicit and
More information about the Python-ideas