encoding of sys.argv ?

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Mon Oct 23 14:23:49 EDT 2006


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.

The `sys.stdin.encoding` approach isn't very robust because this will only
be set if the interpreter can find out what encoding is used on `stdin`. 
That's impossible if the `stdin` is the input from another file.

Make it explicit: Add a command line option to choose the encoding.

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list