Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > encoding problem

Reply
Thread Tools

encoding problem

 
 
Luis Zarrabeitia
Guest
Posts: n/a
 
      05-16-2008

Hi, guys.
I'm trying to read an xml file and output some of the nodes. For that, I'm
doing a
print node.toprettyxml()

However, I get this exception:

===
out.write(tag.toxml())
UnicodeEncodeError: 'ascii' codec can't encode character u'\xba' in position
190: ordinal not in range(12
===

That happens if I "print" it, or send it to stdout, or send it to a file.

How can I fix it?
cat file works perfectly, and I'm using an utf8 terminal.

I'm particularly puzzled that it won't work even if I write to a file opened
in "b" mode. Worst thing is... I don't really need that character, just a
general idea of how the document looks like.

--
Luis Zarrabeitia (aka Kyrie)
Fac. de Matemática y Computación, UH.
http://profesores.matcom.uh.cu/~kyrie
 
Reply With Quote
 
 
 
 
Mike Driscoll
Guest
Posts: n/a
 
      05-16-2008
On May 16, 3:31*pm, Luis Zarrabeitia <(E-Mail Removed)> wrote:
> Hi, guys.
> I'm trying to read an xml file and output some of the nodes. For that, I'm
> doing a
> print node.toprettyxml()
>
> However, I get this exception:
>
> ===
> * * out.write(tag.toxml())
> UnicodeEncodeError: 'ascii' codec can't encode character u'\xba' in position
> 190: ordinal not in range(12
> ===
>
> That happens if I "print" it, or send it to stdout, or send it to a file.
>
> How can I fix it?
> cat file works perfectly, and I'm using an utf8 terminal.
>
> I'm particularly puzzled that it won't work even if I write to a file opened
> in "b" mode. Worst thing is... I don't really need that character, just a
> general idea of how the document looks like.
>
> --
> Luis Zarrabeitia (aka Kyrie)
> Fac. de Matemática y Computación, UH.http://profesores.matcom.uh.cu/~kyrie



I recommend studying up on Python's Unicode methods and the codecs
module. This site actually talks about your specific issue though and
gives pointers:

http://evanjones.ca/python-utf8.html

HTH

Mike
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
encoding problem with BeautifulSoup - problem when writing parsedtext to file Greg Python 9 10-08-2011 03:30 PM
Reading Text File Encoding and converting to Perls internal UTF-8 encoding sln@netherlands.com Perl Misc 2 04-17-2009 11:22 PM
changing JVM encoding; setting -Dfile.encoding doesn't work pasmol@plusnet.pl Java 1 10-08-2004 09:50 PM
Encoding.Default and Encoding.UTF8 Hardy Wang ASP .Net 5 06-09-2004 04:04 PM
Problem encoding/decoding image Slade ASP .Net 1 06-25-2003 09:28 AM



Advertisments