| | |
Qestion on Encoding and Decoding.
![]() |
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.
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.
For German characters I have found it simpler to replace them with acceptable equivalents. Here is an example:
Python Syntax (Toggle Plain Text)
# -*- coding: iso-8859-15 -*- str1 = 'Activest-Aktien-Großbritannien' print str1 # test str1 = str1.replace('ß', 'ss') print str1 # test str2 = 'Überländliche Fracht' print str2 str2 = str2.replace('Ü', 'Ue') str2 = str2.replace('ä', 'ae') print str2
![]() |
Similar Threads
- Slow computer + about:blank homepage (Viruses, Spyware and other Nasties)
- homepage hijack "Search for..." about:blank in address (Viruses, Spyware and other Nasties)
- Trojan Problem (Viruses, Spyware and other Nasties)
- Hijacked Repeatedly "about:blank" - Please Help (Viruses, Spyware and other Nasties)
- Need review of HJT log (Viruses, Spyware and other Nasties)
- Browser Hijack (about:blank) (Viruses, Spyware and other Nasties)
- my HJT log, 2 of them for 2 comp (Viruses, Spyware and other Nasties)
Other Threads in the Python Forum
- Previous Thread: Graphics User Interface for Beginners
- Next Thread: Endless Loops
| Thread Tools | Search this Thread |
abrupt alarm ansi anti approximation array assignment backend beginner binary bluetooth builtin calculator character cmd converter countpasswordentry curved customdialog cx-freeze dan08 data decimals dictionary directory exe file float format function generator getvalue gnu halp heads homework ideas input ip itunes java keycontrol leftmouse line linux list lists loop maintain maze millimeter module mouse mysqlquery number numbers output parsing path pointer prime programming push py2exe pygame python queue random recursion schedule screensaverloopinactive script scrolledtext slicenotation sqlite ssh statistics string strings sudokusolver terminal text thread time tlapse tuple twoup ubuntu unicode urllib urllib2 variable ventrilo vigenere web webservice wikipedia write wxpython xlib






