Message5669

Author pekka.klarck
Recipients pekka.klarck
Date 2010-04-11.21:52:18
SpamBayes Score 3.8918313e-12
Marked as misclassified No
Message-id <1271022740.16.0.789683200408.issue1592@psf.upfronthosting.co.za>
In-reply-to
Content
With CPython 2.6 on Ubuntu I can do:

    args = [ unicode(a, sys.getfilesystemencoding()) for a in sys.argv[1:] ]

but on Jython 2.5.1 that fails with error:

    UnicodeDecodeError: 'ascii' codec can't decode byte 0xe5 in position 0: ordinal not in range(128)

The failure is most likely caused by sys.getfilesystemencoding() returning None on Jython when on CPython it returns correctly UTF-8. The differences don't end there, though, as the arguments are got in different format too:

$ python -c "import sys; print sys.argv[1:]" ä €
['\xc3\xa4', '\xe2\x82\xac']

$ jython -c "import sys; print sys.argv[1:]" ä €
['\xe4', '\u20ac']

The bytes Jython gets would actually be correct without decoding if their type would be unicode and not str. In this format they cannot be used directly:

$ jython -c "import sys; print sys.argv[1] + u'\xe4'" ä
Traceback (most recent call last):
  File "<string>", line 1, in <module>
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position 0: ordinal not in range(128)
History
Date User Action Args
2010-04-11 21:52:20pekka.klarcksetrecipients: + pekka.klarck
2010-04-11 21:52:20pekka.klarcksetmessageid: <1271022740.16.0.789683200408.issue1592@psf.upfronthosting.co.za>
2010-04-11 21:52:20pekka.klarcklinkissue1592 messages
2010-04-11 21:52:18pekka.klarckcreate