What encoding is used when initializing sys.argv?

"Martin v. Löwis" martin at v.loewis.de
Fri Sep 30 18:19:17 EDT 2005


Petr Prikryl wrote:
> I know about the rejected attempt to implement
> sys.argvu. Still, how the sys.argv is filled? What
> encoding is used when parsing the cmd line internally?
> To what encoding is it converted when non ASCII
> characters appear?

Python does not perform any conversion whatsoever.
It has a traditional main() function, with the
char *argv[] argument.

So if you think that the arguments are inherently
Unicode on your system, your question should be
"how does my operating system convert the arguments"?

That, of course, depends on your operating system.
"MS Windows environment" is not precise enough, since
it also depends on the specific incarnation of that
environment. On Windows 9x, I believe the command
line arguments are "inherently" *not* in Unicode,
but in a char array. On Windows NT+, they are Unicode,
and Windows (or is it the MS VC runtime?) converts them
to characters using the CP_ACP code page.

Kind regards,
Martin



More information about the Python-list mailing list