473,573 Members | 3,223 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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;\"> ";
UnicodeDecodeEr ror: 'ascii' codec can't decode byte 0xe2 in position 9:
ordinal not in range(128)

Thanks.

Mar 17 '06 #1
2 2037
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;\"> ";
UnicodeDecodeEr ror: '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"styl e="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=\"widt h:
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;\"> ";
UnicodeDecodeEr ror: '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***********@a cm.org
Mar 17 '06 #3

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

Similar topics

6
26590
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, German, Spanish or Italian. The Polish language is causing me trouble. From what I have read, VB supports UNICODE, in fact it uses UNICODE...
8
2544
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) Now I don't think either string is unicode, but I'm working with win32api so it might be... :) The point is: I know all values will fit in a...
24
9027
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 charcaters from an ASCII perspective. I get the following error: > SQLiteCur.execute(sql, row)
1
4837
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 wondering if anybody has experienced the same issues
4
3312
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: Traceback (most recent call last): File "pokus_1.py", line 5, in ? print str(a) UnicodeEncodeError: 'ascii' codec can't encode character u'\xc1' in
7
3503
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
2927
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 give me. I'm used to writing code like this.
2
4028
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, this deserves a documentation mention. The "socket" module, given a Unicode string, calls the International Domain Name parser, "idna.py", which...
8
3397
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 Unicode or more aptly said, traps only those lines that Perl cannot translate to Latin1. My goal was to trap and then substitute the Unicode character(s)...
7
4013
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
7778
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7687
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8201
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8063
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5585
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5290
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3731
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2203
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1300
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.