473,396 Members | 2,158 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,396 software developers and data experts.

unicode error

I have this python code:
print >> htmlFile, "<div id=\"track" + unicode(1) + "\"
style=\"width: 200px; height:18px;\">";
But that caues this error, and I can't figure it out why. Any help is
appreicate
File "./run.py", line 193, in ?
print >> htmlFile, "<div id=\"track" + unicode(1) + "\"
style=\"width: 200px; height:18px;\">";
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 9:
ordinal not in range(128)

Thanks.

Mar 17 '06 #1
2 2029
Al************@gmail.com wrote:
I have this python code:
print >> htmlFile, "<div id=\"track" + unicode(1) + "\"
style=\"width: 200px; height:18px;\">";
But that caues this error, and I can't figure it out why. Any help is
appreicate
File "./run.py", line 193, in ?
print >> htmlFile, "<div id=\"track" + unicode(1) + "\"
style=\"width: 200px; height:18px;\">";
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 9:
ordinal not in range(128)

Thanks.

Hi,
I tried and it worked (wrote into the file:<div id="track1"style="width:
200px; height:18px;">).
Can you try to isolate exactly what part of the code is wrong ?
jm
Here is the complete code:
htmlfile=file('jmbc.txt','w')
print >> htmlfile, "<div id=\"track" + unicode(1) + "\"style=\"width:
200px; height:18px;\">";
htmlfile.close()
Mar 17 '06 #2
Al************@gmail.com wrote:
I have this python code:
print >> htmlFile, "<div id=\"track" + unicode(1) + "\"
style=\"width: 200px; height:18px;\">";
But that caues this error, and I can't figure it out why. Any help is
appreicate
File "./run.py", line 193, in ?
print >> htmlFile, "<div id=\"track" + unicode(1) + "\"
style=\"width: 200px; height:18px;\">";
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 9:
ordinal not in range(128)

Thanks.

You can make the code easier to read by using single quotes to quote
strings with double quotes inside:

print >> htmlFile, ('<div id="track' + unicode(1) +
'" style="width: 200px; height:18px;">')

Or even better:

print >> htmlFile, (u'<div id="track%s" '
u'style="width: 200px; height:18px;">') % unicode(1)

The unicode(1) confuses me -- you are converting an integer to its
string representation in unicode (do you know that?), not picking a
particular character.

print >> htmlFile, (u'<div id="track%d" style="width: 200px; '
u'height:18px;">') % (1,)

And if you don't mean to be writing unicode, you could use:

print >> htmlFile, ('<div id="track%d" style="width: 200px; '
'height:18px;">') % (1,)

--Scott David Daniels
sc***********@acm.org
Mar 17 '06 #3

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

Similar topics

6
by: ..... | last post by:
I have an established program that I am changing to allow users to select one of eight languages and have all the label captions change accordingly. I have no problems with English, French, Dutch,...
8
by: Ivan Voras | last post by:
When concatenating strings (actually, a constant and a string...) i get the following error: UnicodeDecodeError: 'ascii' codec can't decode byte 0xfc in position 1: ordinal not in range(128) ...
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...
1
by: jrs_14618 | last post by:
Hello All, This post is essentially a reply a previous post/thread here on this mailing.database.myodbc group titled: MySQL 4.0, FULL-TEXT Indexing and Search Arabic Data, Unicode I was...
4
by: Petr Jakes | last post by:
Hi, I am using Python 2.4.3 on Fedora Core4 and "Eric3" Python IDE .. Below mentioned code works fine in the Eric3 environment. While trying to start it from the command line, it returns: ...
7
by: aine_canby | last post by:
Hi, Im totally new to Python so please bare with me. Data is entered into my program using the folling code - str = raw_input(command) words = str.split() for word in words:
9
by: Jim | last post by:
Hello, I'm trying to write exception-handling code that is OK in the presence of unicode error messages. I seem to have gotten all mixed up and I'd appreciate any un-mixing that anyone can...
2
by: John Nagle | last post by:
Here's a strange little bug. "socket.getaddrinfo" blows up if given a bad domain name containing ".." in Unicode. The same string in ASCII produces the correct "gaierror" exception. Actually,...
8
by: rkellerjr | last post by:
I have just delved into the world of Unicode versus Latin1. I've written a quick program (ignore some of the messy code, it's been a work in progress) that traps a string of text that contains...
7
by: 7stud | last post by:
Based on this example and the error: ----- u_str = u"abc\u9999" print u_str UnicodeEncodeError: 'ascii' codec can't encode character u'\u9999' in position 3: ordinal not in range(128) ------
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.