From: Peter Kleiweg on

How do I set the string encoding for os.system to anything other then UTF-8?


(peter) ~ echo $LANG
nl_NL(a)euro
(peter) ~ python3
Python 3.1.1 (r311:74480, Oct 2 2009, 11:50:52)
>>> '\N{EURO SIGN}'
'�'
>>> import os
>>> os.system('echo \N{EURO SIGN}')
�?�
0
>>>


--
Peter Kleiweg
From: Martin v. Loewis on
Am 25.06.2010 17:13, schrieb Peter Kleiweg:
> How do I set the string encoding for os.system to anything other then UTF-8?

You shouldn't have to set it, as it should use your locale's encoding.
In 3.1.2, it will.

For the moment, you can encode the string explicitly, and pass a byte
string.

Regards,
Martin
From: Peter Kleiweg on
Martin v. Loewis schreef op de 27e dag van de zomermaand van het jaar 2010:

> Am 25.06.2010 17:13, schrieb Peter Kleiweg:
> > How do I set the string encoding for os.system to anything other then UTF-8?
>
> You shouldn't have to set it, as it should use your locale's encoding.
> In 3.1.2, it will.
>
> For the moment, you can encode the string explicitly, and pass a byte
> string.

That doesn't work

Python 3.1.1 (r311:74480, Oct 2 2009, 11:50:52)
>>> import os
>>> os.system('echo \N{EURO SIGN}'.encode('iso-8859-15'))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: must be string, not bytes


--
Peter Kleiweg L:NL,af,da,de,en,ia,nds,no,sv,(fr,it) S:NL,de,en,(da,ia)
info: http://www.let.rug.nl/kleiweg/ls.html
From: Martin v. Loewis on
>> For the moment, you can encode the string explicitly, and pass a byte
>> string.
>
> That doesn't work

I only have 3.1.2 to test at the moment. I suggest trying to use the
subprocess module instead.

Regards,
Martin
From: Lawrence D'Oliveiro on
In message <alpine.DEB.1.10.1006251708470.3765(a)localhost>, Peter Kleiweg
wrote:

> How do I set the string encoding for os.system to anything other then
> UTF-8?

Works for me (on Debian Unstable):

ldo(a)theon:~> echo $LC_ALL
en_NZ.utf8
ldo(a)theon:~> python3.1
Python 3.1.2 (r312:79147, May 8 2010, 13:27:06)
[GCC 4.4.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.system('echo \N{EURO SIGN}')

0
>>> '\N{EURO SIGN}'
'€'
>>>