encoding of sys.argv ?

Steve Holden steve at holdenweb.com
Mon Oct 23 14:22:00 EDT 2006


Jiba wrote:
> Hi all,
> 
> 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 ?
> 
> Jiba

Here's what I see in a Windows command prompt interactive session:

Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)] on 
win32
Type "help", "copyright", "credits" or "license" for more information.
Started with C:/Steve/.pythonrc
  >>> import sys
  >>> sys.stdin.encoding
'cp437'
  >>> sys.getdefaultencoding()
'ascii'
  >>>

But in a Cygwin command window on the same machine I see

import syPython 2.5b2 (trunk:50713, Jul 19 2006, 16:04:09)
[GCC 3.4.4 (cygming special) (gdc 0.12, using dmd 0.125)] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
sStarted with C:/Steve/.pythonrc
  >>> import sys
  >>> sys.stdin.encoding
'US-ASCII'
  >>> sys.getdefaultencoding()
'ascii'
  >>>

The strings in sys.argv are encoded the same as the standard input, I 
bleieve.

regards
  Steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd          http://www.holdenweb.com
Skype: holdenweb       http://holdenweb.blogspot.com
Recent Ramblings     http://del.icio.us/steve.holden




More information about the Python-list mailing list