473,394 Members | 1,740 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

unicode and os.system

I've got a rather large python script that I write and maintain. It has
some interaction with other programmes on the linux/kde desktop through
the dcop interface. This script also uses the gettext module to enable
the output of the script to be translated into several languages,
including utf-8 encoded text.

However, when I issue a dcop call to an application (which is a docker
application that can display text above an icon), the operation fails with:

Traceback (most recent call last):
File "/home/matt/karamba/lwbkup/liquid_weather.py", line 2970, in widgetUpdated
os.system('dcop kxdocker docker changeTextByName Current "%s : %s"' %(_(situtext), weather.temperature()))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xb0 in position 2:
ordinal not in range(128)

_(situtext) is a variable containing a unicode string.

My python environment has ascii as its encoding for stdout
import sys
print sys.stdout.encoding

ANSI_X3.4-1968

the dcop call I'm using requires a QString variable where the _(situtext)
is.

Can anyone help me to work through this issue? I'm a bit lost as to where
to start.

Thanks

Matt
Sep 2 '05 #1
4 7185
Dumbkiwi wrote:
Can anyone help me to work through this issue? I'm a bit lost as to where
to start.


If you want to convert it to UTF-8, then do so with

u.decode('utf-8')

--
Erik Max Francis && ma*@alcyone.com && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
Liberty is the right to do whatever the law permits.
-- Charles Louis Montesquieu
Sep 2 '05 #2
On Fri, 02 Sep 2005 16:11:48 -0700, Erik Max Francis wrote:
Dumbkiwi wrote:
Can anyone help me to work through this issue? I'm a bit lost as to where
to start.


If you want to convert it to UTF-8, then do so with

u.decode('utf-8')


I've tried that previously, and get:

Traceback (most recent call last):
File "/home/matt/karamba/lwbkup/liquid_weather.py", line 2765, in initWidget
os.system('dcop kxdocker docker addIcon Current %s "%s : %s" /dev/null GIcon lwp none none none none' %(icopath, QString(situtext.decode('utf-8'), weather.temperature()))
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe4' in
position 9: ordinal not in range(128)

Thanks for responding though.

Matt
Sep 2 '05 #3
Dumbkiwi wrote:
I've tried that previously, and get:

Traceback (most recent call last):
File "/home/matt/karamba/lwbkup/liquid_weather.py", line 2765, in initWidget
os.system('dcop kxdocker docker addIcon Current %s "%s : %s" /dev/null GIcon lwp none none none none' %(icopath, QString(situtext.decode('utf-8'), weather.temperature()))
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe4' in
position 9: ordinal not in range(128)

Thanks for responding though.


That means one of the other things you're trying to print with %s is
also a Unicode string, and it contains non-ASCII characters. Try
printing their types to see which one it is.

--
Erik Max Francis && ma*@alcyone.com && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
Liberty is the right to do whatever the law permits.
-- Charles Louis Montesquieu
Sep 2 '05 #4
I think you need
u.encode('utf-8')
..encode() turns unicode into a byte string, .decode() turns a byte string into
unicode.

Jeff

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)

iD8DBQFDGRR8Jd01MZaTXX0RAgNIAJ4/h8DGTKhMn7yNpSFz9CistqflAQCeKhIb
gXF+JxnGfkGohQr6PRzotmo=
=KCun
-----END PGP SIGNATURE-----

Sep 3 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: sebastien.hugues | last post by:
Hi I would like to retrieve the application data directory path of the logged user on windows XP. To achieve this goal i use the environment variable APPDATA. The logged user has this name:...
4
by: Majed | last post by:
Hi , all I'm trying to write unicode to a file for another app (not developed with vs2003) to read it. I used StreamWriter with unicode encoding.but I was surprised that the streamwriter adds FFFE...
3
by: hunterb | last post by:
I have a file which has no BOM and contains mostly single byte chars. There are numerous double byte chars (Japanese) which appear throughout. I need to take the resulting Unicode and store it in a...
12
by: Onega | last post by:
Hi I create a simple win32 project (VC2003, windows2003(English) , and do simple paint in WM_PAINT message, when the project use multi-character set, it is OK. but when I change to UNICODE,...
1
by: David Dvali | last post by:
Hello. I have a problem with sending Unicode text in mail message. So what I do: First of all I have some template file like this: ================================= <html> <head><title>Test...
18
by: Ger | last post by:
I have not been able to find a simple, straight forward Unicode to ASCII string conversion function in VB.Net. Is that because such a function does not exists or do I overlook it? I found...
6
by: Jeff | last post by:
Hi - I'm setting up a streamreader in a VB.NET app to read a text file and display its contents in a multiline textbox. If I set it up with System.Text.Encoding.Unicode, it reads a unicode...
8
by: Andy | last post by:
Hello All: I have a windows application that I need to encode a string using Unicode. The example I have been given to use is a Web-Version. Below is the webcode. ...
6
by: msdnuniv | last post by:
Hello everybody, since days i try to convert Unicode-Strings in VB.NET to ANSI which should be processable in VB6 and converted to unicode again. It should be possible with any codepage, e.g....
29
by: Ioannis Vranos | last post by:
Hi, I am currently learning QT, a portable C++ framework which comes with both a commercial and GPL license, and which provides conversion operations to its various types to/from standard C++...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.