[Python-ideas] Python 3 open() text files: make encoding parameter optional for cross-platform scripts

Oleg Broytman phd at phdru.name
Sun Jun 9 10:51:22 CEST 2013


Hi!

On Sat, Jun 08, 2013 at 06:10:30PM -0700, Andrew Barnert <abarnert at yahoo.com> wrote:
> if I create a text file with "type >foo.txt" or Notepad on a Russian system, I won't be able to open it on that English or Greek system either??? but at least I'll be able to open it on Python on the same Russian system.

   He-he, wrong! If you create a text file on a Russian system with
"type >foo.txt" you get a file in a different encoding comparing with a
file created in Notepad. Notepad creates files in the system encoding --
code page 1251 on Russian systems; "console" works with OEM encoding
which in this example is cp 866.
   So if you create a text file on a Russian system with "type >foo.txt"
and want to open it in Python you have to know in advance that the file
is not in the system encoding but in OEM encoding, and what that OEM
encoding is.
   I don't know how to query the OEM encoding. I'm sure pywin32 can do
that, but how?

Oleg.
-- 
     Oleg Broytman            http://phdru.name/            phd at phdru.name
           Programmers don't die, they just GOSUB without RETURN.


More information about the Python-ideas mailing list