25 ms·
> Your setup script is not going to run out of file descriptors because you wrote open("README.md").read(). How about even simpler (python3) Path("readme.md
by perfunctory 6y ago
> Your setup script is not going to run out of file descriptors because you wrote open("README.md").read().
How about even simpler (python3)
Path("readme.md").read_text()
Ta-da. I don't even have to worry about opening files, let alone closing.
- xenonite 6y agoTo complete your comment, let us import pathlib. from pathlib import Path Path("readme.md").read_text() The functions read_text and the similar write_text, read_bytes, write_bytes are new in Python 3.5. https://docs.python.org/3/library/pathlib.html#pathlib.Path.read_text https://docs.python.org/3/library/pathlib.html#pathlib.Path....
- pansa2 6y agoI wasn’t aware of these functions. At first glance, their addition to Python seems to be a significant violation of “one-- and preferably only one --obvious way to do it”. What are the advantages of `read_text` over the traditional `file` read methods?