[Tutor] sys.getfilesystemencoding()

Albert-Jan Roskam fomcl at yahoo.com
Wed Dec 19 11:43:59 CET 2012



>________________________________
> From: eryksun <eryksun at gmail.com>
>To: Albert-Jan Roskam <fomcl at yahoo.com> 
>Cc: Python Mailing List <tutor at python.org> 
>Sent: Tuesday, December 18, 2012 4:07 PM
>Subject: Re: [Tutor] sys.getfilesystemencoding()
> 
>On Tue, Dec 18, 2012 at 8:13 AM, Albert-Jan Roskam <fomcl at yahoo.com> wrote:
>>
>>In windows xp, the characters can, apparently, not be represented
>>in this encoding called 'mbcs'.
>
>MBCS (multibyte character set) refers to the locale encoding on
>Windows. CPython encodes to MBCS via the Win32 function
>WideCharToMultiByte, with the CP_ACP code page (i.e. the system
>default 'ANSI' encoding):
>
>unicodeobject.c, encode_mbcs (3877-3884):
>http://hg.python.org/cpython/file/8803c3d61da2/Objects/unicodeobject.c#l3843
>
>WideCharToMultiByte:
>http://msdn.microsoft.com/en-us/library/windows/desktop/dd374130


Hi again,

Thank you for your reply. Oscar, also thanks for your reply; our e-mails yesterday. So MBCS is just a collective noun for whatever happens to be the installed/available codepage of the host computer (at least with CP_ACP)?

I didn't know anything about wintypes and I find it quite hard to understand! I am trying to write a ctypes wrapper for WideCharToMultiByte. It takes a unicode path name and (is supposed to) returns a bytestring using the utf8 codepage: http://pastebin.com/SEr4Wec9 . The code is kinda verbose, but I hope this makes it easier to read.
Does this makes sense at all? As for now, the program returns an error code (oddly, zero is an error code here).

I chose CP_UTF8 instead of CP_ACP because I don't want the conversion to depend on some (arbitrary) system default Windows ANSI code page.

Regards,
Albert-Jan


More information about the Tutor mailing list