On 2021-09-06 10:50, Christopher Barker wrote:
I think the point here is not the context manager, but rather, having
the reader open the file itself, rather than taking an already open
file-like object.
I agree, and I think having such capability is very useful. I'm always
annoyed by things like json.load that require me to open the file
separately. There isn't much genuine ambiguity here: I think it's fine
to treat strings and Path instances as meaning "this is a filename, open
it" and if it's not specifically one of those, then treat it as a
file-like object and try to read it.
Alternatively, as mentioned on this thread, there's no reason that all
these functions that require you to open the file yourself couldn't just
grow a new method that's explicitly documented to accept a filename
instead of an open file.
But I don't see how requiring the user to open the file first on their
own gains anything. In my experience 90% of the time that's just more
cumbersome and I would prefer the library to handle the entire file
operation internally (like pandas does).
--
Brendan Barnwell
"Do not follow where the path may lead. Go, instead, where there is no
path, and leave a trail."
--author unknown
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/73P4PFAG7IDCSXPWSCODPKGCB3VNICFD/
Code of Conduct: http://python.org/psf/codeofconduct/