encoding of sys.argv ?

Leo Kislov Leo.Kislov at gmail.com
Mon Oct 23 17:09:39 EDT 2006


Marc 'BlackJack' Rintsch wrote:
> In <20061023130504.26823717 at autremonde>, Jiba wrote:
>
> > I am desperately searching for the encoding of sys.argv.
> >
> > I use a Linux box, with French UTF-8 locales and an UTF-8 filesystem.
> > sys.getdefaultencoding() is "ascii" and sys.getfilesystemencoding() is
> > "utf-8". However, sys.argv is neither in ASCII (since I can pass French
> > accentuated character), nor in UTF-8. It seems to be encoded in
> > "latin-1", but why ?
>
> There is no way to determine the encoding.  The application that starts
> another and sets the arguments can use any encoding it likes and there's
> no standard way to find out which it was.

There is standard way: nl_langinfo function
<http://www.opengroup.org/onlinepubs/009695399/functions/nl_langinfo.html>
The code in pythonrun.c properly uses it find out the encoding. The
other question if Linux or *BSD distributions confirm to the standard.

  -- Leo.




More information about the Python-list mailing list