473,320 Members | 1,823 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,320 software developers and data experts.

Re: problem with unicode

On Apr 25, 9:15 pm, "andreas.prof...@googlemail.com"
<andreas.prof...@googlemail.comwrote:
Hi everybody,

I'm using the win32 console and have the following short program
excerpt

# media is a binary string (mysql escaped zipped file)
print media

x$B%o%f%m(B[$B%h(B ...
(works)
print unicode(media)

UnicodeDecodeError: 'ascii' codec can't decode byte 0x9c in position
1: ordinal not in range(128)
(ok i guess print assumes you want to print to ascii)
Guessing is no substitute for reading the manual.

print has nothing to do with your problem; the problem is
unicode(media) -- as you specified no encoding, it uses the default
encoding, which is ascii [unless you have been mucking about, which is
not recommended]. As the 2nd byte is 0x9c, ascii is going nowhere.

>
print unicode(media).encode('utf-8')

UnicodeDecodeError: 'ascii' codec can't decode byte 0x9c in position
1: ordinal not in range(128)
(why does this not work?)
Already unicode(media) "doesn't work", so naturally(?)
unicode(media).whatever() won't be better -- whatever won't be called.
>
# mapString is a unicode string (i think at least)>print "'" + mapString + "'"

' yu_200703_hello\ 831 v1234.9874 '
mystr = "%s %s" % (mapString, media)

UnicodeDecodeError: 'ascii' codec can't decode byte 0x9c in position
1: ordinal not in range(128)
mystr = "%s %s" % (mapString.encode('utf-8'), media.encode('utf-8'))

UnicodeDecodeError: 'ascii' codec can't decode byte 0x9c in position
1: ordinal not in range(128)
This is merely repeating the original problem.
>
I don't know what to do. I just want to concatenate two string where
apparently one is a binary string, the other one is a unicode string
and I always seem to get this error.

Any help is appreciated :)
We need a clue or two; do this and let us know what it says:

print type(media), repr(media)
print type(mapString), repr(mapString)
import sys; print sys.stdout.encoding

Also you say that "print media" works. Do you mean that it produces
some meaningful text that you understand? What I see on the screen in
Google Groups is the following 6 characters:
LATIN SMALL LETTER X
KATAKANA LETTER WA
KATAKANA LETTER YU
KATAKANA LETTER RO
LEFT SQUARE BRACKET
KATAKANA LETTER YO
Is that what you see?

What is it that you call "win32 console"?
Jun 27 '08 #1
0 1670

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

Similar topics

4
by: Alban Hertroys | last post by:
Another python/psycopg question, for which the solution is probably quite simple; I just don't know where to look. I have a query that inserts data originating from an utf-8 encoded XML file....
11
by: Marian Aldenhövel | last post by:
Hi, I am very new to Python and have run into the following problem. If I do something like dir = os.listdir(somepath) for d in dir: print d The program fails for filenames that contain...
8
by: Francis Girard | last post by:
Hi, For the first time in my programmer life, I have to take care of character encoding. I have a question about the BOM marks. If I understand well, into the UTF-8 unicode binary...
48
by: Zenobia | last post by:
Recently I was editing a document in GoLive 6. I like GoLive because it has some nice features such as: * rewrite source code * check syntax * global search & replace (through several files at...
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...
6
by: peter pilsl | last post by:
postgres 7.3.2 I store unicode-data in postgresql. The data is retrieved via webinterfaces, processed with perl and then stored in postgresql (and viceversa). All is going nice with one...
24
by: ChaosKCW | last post by:
Hi I am reading from an oracle database using cx_Oracle. I am writing to a SQLite database using apsw. The oracle database is returning utf-8 characters for euopean item names, ie special...
7
by: Rymfax | last post by:
I would really appreciate it if someone could help me figure out what I'm doing wrong trying to PInvoke SetupDiEnumDriverInfo. All the other PInvokes i've done up to this point work fine. Whenver...
3
by: sophie_newbie | last post by:
Hi, I want to store python text strings that characters like "é" "Č" in a mysql varchar text field. Now my problem is that mysql does not seem to accept these characters. I'm wondering if there...
3
by: Jorgen Bodde | last post by:
Hi All, I am relatively new to python unicode pains and I would like to have some advice. I have this snippet of code: def playFile(cmd, args): argstr = list() for arg in...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work

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.