4 ms·
Edit: I didn't try to handle files with Python for a long time. All of the following is stuff that can change as an ecosystem matures. All that may not hold any
by marcosdumay 8y ago
Edit: I didn't try to handle files with Python for a long time. All of the following is stuff that can change as an ecosystem matures. All that may not hold anymore.
It's better in some ways. But then, I gave up long ago on manipulating files with Python, because Python 3 simply decided that anything on my filesystem is utf-8 by default.
Want to get an stream out of a file? Better have utf-8 content. Otherwise all the documentation will be buried 15 meters deep, outdated on some aspects and dependent on some not-released yet features.
Want to name a file? Better have an utf-8 name. I gave-up on python before I was able to open a file with a name that doesn't conform to utf-8.
Want to read a line at a time? Sorry, we only do that to text. Go get an utf-8 file.
Want to match with a regular expression or parse it somehow? Sorry, we only do that to text.
And so on.
- ak217 8y agoPerhaps your information is out of date? I think none of what you said is true. Maybe some of it was true in the past. > Want to get an stream out of a file? Better have utf-8 content. Otherwise all the documentation will be buried 15 meters deep, outdated on some aspects and dependent on some not-released yet features. f = open("myfile.txt", "r", encoding=ENCODING) > Want to name a file? Better have an utf-8 name. I gave-up on python before I was able to open a file with a name that doesn't conform to utf-8. export NAME="$(head -c 5 /dev/urandom)"; touch "$NAME"; python -c 'import os; open(os.environ["NAME"])' > Want to read a line at a time? Sorry, we only do that to text. Go get an utf-8 file. fh = open("foo", "rb"); lines=[l for l in fh] > Want to match with a regular expression or parse it somehow? Sorry, we only do that to text. import re; re.match(b"abc", b"abcdef")
- marcosdumay 8y agoYes, my experience is probably out of date.