GIDForums  

Go Back   GIDForums > Computer Programming Forums > Python Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 31-Jan-2008, 14:48
noa noa is offline
New Member
 
Join Date: Jan 2008
Posts: 3
noa is on a distinguished road

Python Unicode problem


Hi!

I would like to read a file, which may or may not contain non-ascii characters such as umloats, and then output it in an ascii format.

I have tried using someword.encode('ascii','replace'), but it reports

Code:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xf6 in position 1: ordinal not in range(128)

Any suggestions?

Thanks!
  #2  
Old 31-Jan-2008, 18:48
crystalattice's Avatar
crystalattice crystalattice is offline
Flame War Instigator
 
Join Date: Apr 2004
Location: San Diego
Posts: 1,534
crystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nice

Re: Python Unicode problem


Are you using the Unicode types of Python? You might want to take a look at these:
http://www.reportlab.com/i18n/python..._tutorial.html
http://www.amk.ca/python/howto/unicode
__________________
Common Sense v2.0-Striving to make the world a little bit smarter.
  #3  
Old 31-Jan-2008, 21:50
noa noa is offline
New Member
 
Join Date: Jan 2008
Posts: 3
noa is on a distinguished road

Re: Python Unicode problem


I thought that `encode' WAS a function of a unicode type?
  #4  
Old 01-Feb-2008, 13:44
crystalattice's Avatar
crystalattice crystalattice is offline
Flame War Instigator
 
Join Date: Apr 2004
Location: San Diego
Posts: 1,534
crystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nice

Re: Python Unicode problem


It is. Take a look at the second link I gave. About halfway down the page it shows the encode method and gives an error example that sounds exactly like what you encountered.
__________________
Common Sense v2.0-Striving to make the world a little bit smarter.
  #5  
Old 01-Feb-2008, 15:12
noa noa is offline
New Member
 
Join Date: Jan 2008
Posts: 3
noa is on a distinguished road

Re: Python Unicode problem


Yes, I had seen that: in fact it is EXACTLY my error. Unfortunately, I AM using 'replace' and STILL getting the same thing!

Code:
>>> u.encode('ascii') Traceback (most recent call last): File "<stdin>", line 1, in ? UnicodeEncodeError: 'ascii' codec can't encode character '\ua000' in position 0: ordinal not in range(128) >>> u.encode('ascii', 'ignore') 'abcd' >>> u.encode('ascii', 'replace') '?abcd?'
 

Recent GIDBlogNARMY by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Neutral Python book - the Quest for the Impossible? Kimmo Python Forum 1 04-Aug-2007 12:56
Looking for opinions crystalattice Miscellaneous Programming Forum 6 27-Sep-2006 21:02
Help with syntax errors PeteGallo C Programming Language 7 08-Aug-2005 20:30
MAPI Unicode problem ifulcrum CPP / C++ Forum 0 25-Jul-2005 04:39
MAPI Unicode problem ifulcrum MS Visual C++ / MFC Forum 0 25-Jul-2005 04:38

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 15:47.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.