3 ms·
> Again, not surprising when you realize the default encoding on (en_US) Windows is cp1252. By "the encoding" you're referring to PYTHONIOENCODING, right? Som
by mehrdadn 7y ago
> Again, not surprising when you realize the default encoding on (en_US) Windows is cp1252.
By "the encoding" you're referring to PYTHONIOENCODING, right?
Somehow PYTHONIOENCODING is "not specific to Python at all"?
- oefrha 7y agoPYTHONIOENCODING is an override env var you can set. cp1252 being the default on Windows is of course not Python-specific, it’s convention set by Microsoft. In fact, you do realize cp1252 aka Latin-1 was even the default encoding used by the HTML spec before the advent of HTML5 (postdates Python3)? Creators of Python3 certainly didn’t set this default to mess with you.
- mehrdadn 7y agoNo, this is just insane Python behavior. There's clearly nothing in the Windows I/O path that's doing this, and if it's a "convention", it's not even one that Python 2 has followed! PHP doesn't do it this way: php -r "echo json_decode(chr(34).'\u00DD'.chr(34));" Ruby doesn't do it this way either: ruby -e "puts \"\u00DD\"" Neither does MSYS2's Bash: printf '\u00DD' Neither does Node.js: node --eval="process.stdout.write('\u00DD');" Hell, even Python 2's behavior of raising an error is more sane than just encoding in cp1252 silently and expecting every developer to somehow know the resulting byte sequence is going to be different on each platform: python3 -c "print(u'\u00DD')" Obviously, I'm not the only one who thinks that whatever this (ancient?) so-called "convention" is, it's actively harmful enough to avoid in 2019. And as if that's not enough, that's not even the end of it. Even literally writing a string to a file (with no console or stdio in between!!) ends up producing a completely different file depending on which platform the code is run on: python3 -c "open('Temp.bin', 'w+').write(u'\u00DD')" && xxd Temp.bin && rm Temp.bin How is any programmer supposed to deal with this insanity? A program writes to a file, but produces files with completely different contents depending on the platform? Heaven help you if you try to interacting with a program in another language. At least with newlines, as painful as they are, most people know and recognize how to deal with them. But dealing with that mess is enough, and not a reason to make the situation even worse?! It's almost as if they took the CRLF issue and then went "Hmm, that's not fair to CR or LF, we need to do this to even more characters." Somehow we have all this nonsense in the name of "fixing" strings from Python 2. Instead of finding a better convention or at least leaving the existing behavior alone, Python 3—which is intended to let people write cross-platform code!—actively embraced it and botched Python 2's safe behavior, making programs produce garbled output completely silently... and blaming it on the stupid developer for trying to write a broken cross-platform program without first getting a PhD on the history of Code Pages on Windows.