by schoen · 11y ago · 0 comments
open("/dev/urandom").read(20)
and was confronted with
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 2: invalid start byte
If I had realized at the time that this error would be averted with
open("/dev/urandom", "rb").read(20)
I might have felt more charitable and less shocked (although I can see in retrospect that there's quite a good reason for this error, I might have preferred for the default file type to be binary -- presumably something that was debated extensively inside the Python 3 development effort).
This change only made that mistake visible on other systems.
Edit: Actually python doesn't even mention windows. It's simply "Add a 'b' to the mode for binary files." (in python 2.7 documentation) According to the docs it should be specified regardless.