944,054 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Unsolved
  • Views: 1822
  • Python RSS
Nov 13th, 2006
0

Qestion on Encoding and Decoding.

Expand Post »
Hi all,

Platform: winxp
Version: Python 2.3

I have a task of reading files in a folder and creating an one excel
file with sheets, one sheet per file, with sheet named as filename. I
am facing problem in handling special characters. I am using XLRD and
XLW package to read/write from/to file. But facing problem in handling
special characters. I am getting encode error.

UnicodeDecodeError 'ascii' codec can't encode character u'\xdf' in
position 19: ordinal not in range(128)
row: 76

the cell value at rowx = 76, colx = 0 is
'Activest-Aktien-Großbritannien'

I used Latin-1 encoding, but after the file is created I get an error
'Unable to read the file'.

When I get the exception I want to format the string so that I can use
it to write to a file and also query database.

Can anybody guide how to solve this problem. what encoding I should
use, and after wring to file I should the same special character.

Also python IDLE is able to output the same character corretly when I
say print and why not I?

Any suggestions would be greatly appreciated.

thanks.
regards,
kath.
Similar Threads
Reputation Points: 19
Solved Threads: 34
Posting Whiz in Training
katharnakh is offline Offline
237 posts
since Jan 2006
Nov 14th, 2006
0

Re: Qestion on Encoding and Decoding.

For German characters I have found it simpler to replace them with acceptable equivalents. Here is an example:
Python Syntax (Toggle Plain Text)
  1. # -*- coding: iso-8859-15 -*-
  2.  
  3. str1 = 'Activest-Aktien-Großbritannien'
  4. print str1 # test
  5. str1 = str1.replace('ß', 'ss')
  6. print str1 # test
  7.  
  8. str2 = 'Überländliche Fracht'
  9. print str2
  10. str2 = str2.replace('Ü', 'Ue')
  11. str2 = str2.replace('ä', 'ae')
  12. print str2
Reputation Points: 404
Solved Threads: 180
Nearly a Posting Virtuoso
bumsfeld is offline Offline
1,422 posts
since Jul 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: Graphics User Interface for Beginners
Next Thread in Python Forum Timeline: Endless Loops





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC