Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

just plain

    for line in yourfile:
        print line
with yourfile containing non-ascii characters and running it in windows console.


That sounds like a limitation of the Windows console, not the programming language.


It's a limitation of how the programming language interacts with the Windows console, and it's a mistake. If you are writing potentially-garbled strings directly to the console, there is already no guarantee that the output will properly reflect the string or e.g. copying and pasting will work correctly, because the string could include backspace characters, or a ton of newlines. Therefore it doesn't make sense to do anything other than make a 'best effort' attempt when rendering strings to the console, including with Unicode handling. If it works, great, but if the string is invalid Unicode, that's only one of multiple problematic cases, so what exactly is throwing an exception supposed to accomplish? Python should use replacement characters by default in this case.


Stop using the Windows console. Or fix it. More rational than a breaking upgrade to Python 3.


Fixing the Windows console rather than upgrading to Python 3 is the only sensible choice.

</s>


It is, and Java has similar problems on Windows. The Windows console can be switched to Unicode, but by default, it emulates the IBM 5150 PC character set, circa 1980. It's not even ISO LATIN-1.

Works fine on Linux.


Windows console shpport is broken on python 3 too on many versions. Click the library can print unicode to the console on windows however. No python 3 needed.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: