473,699 Members | 2,436 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 2042
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
26622
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 internally, which means that ANY character in pretty much any language should be readable from a UNICODE...
8
2551
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 particular code page (iso-8859-2), so how do I change the 'ascii' codec in the above error into something...
24
9056
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
4848
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
3319
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
3509
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
2935
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
4034
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 has a a whole error system of its own. The IDNA documentation says that "Furthermore, the socket...
8
3405
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) within that string with something to my liking from the Latin1 character set. For example, Perl will...
7
4019
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
8622
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9184
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9045
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8930
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6538
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5878
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4382
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3062
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
2
2359
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.