| | |
unicode encoding in script
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jun 2009
Posts: 3
Reputation:
Solved Threads: 0
so I have a script that is taking input from a text file and using it to populate an excel spreadsheet. it keeps giving me a UnicodeDecodeError, dying on the ± symbol, I'm assuming its not in the codec that is being used:
im using the xlwt package for writign to excel.
I've tried to encode it but unsure which codec to use. any recommendations for how to handle it?
the code that dies is when it saves the workbook with that symbol in the line
im using the xlwt package for writign to excel.
Python Syntax (Toggle Plain Text)
workBook.save((self.output)) File "C:\Python25\lib\site-packages\xlwt\Workbook.py", line 634, in save doc.save(filename, self.get_biff_data()) File "C:\Python25\lib\site-packages\xlwt\Workbook.py", line 609, in get_biff_data shared_str_table = self.__sst_rec() File "C:\Python25\lib\site-packages\xlwt\Workbook.py", line 571, in __sst_rec return self.__sst.get_biff_record() File "C:\Python25\Lib\site-packages\xlwt\BIFFRecords.py", line 53, in get_biff_record self._add_to_sst(s) File "C:\Python25\Lib\site-packages\xlwt\BIFFRecords.py", line 66, in _add_to_sst u_str = upack2(s, self.encoding) File "C:\Python25\Lib\site-packages\xlwt\UnicodeUtils.py", line 50, in upack2 us = unicode(s, encoding) UnicodeDecodeError: 'ascii' codec can't decode byte 0xb1 in position 59: ordinal not in range(128)
I've tried to encode it but unsure which codec to use. any recommendations for how to handle it?
the code that dies is when it saves the workbook with that symbol in the line
•
•
Join Date: Oct 2008
Posts: 8
Reputation:
Solved Threads: 0
It seems to be trying to use ascii for some reason and not unicode. What is the encoding variable set to? Setting it to utf-8 should work.
You might like this guide to unicode in Python 2 - http://farmdev.com/talks/unicode/
You might like this guide to unicode in Python 2 - http://farmdev.com/talks/unicode/
Last edited by god0fgod; Sep 16th, 2009 at 6:27 pm.
![]() |
Similar Threads
- StreamReader and Position (C#)
- ANSI to UNICODE encoding (ColdFusion)
- Escape and Unescape / Handling (C)
- C preprocessor (C)
- JEditorPane Display Errors (Java)
Other Threads in the Python Forum
- Previous Thread: Is Python a good choice?
- Next Thread: How can webservice maintain session
| Thread Tools | Search this Thread |
2007 accessdenied actionlistener anti apax array bash beginner binary book c++ calling code console conversion convert csv cturtle curved cx-freeze data dictionary dynamic enter event examples excel external file filename function generator google gui homework infiniteloop infosec input java javascript jlabel keycontrol library line linux list loan microphone microsoft movingranges mysql mysqldb newb packing parameters plugins powerpoint programming projects prompt push py2exe pygame pygtk python random raw_input read redirect return reverse rubyconf silverlight simple sprite ssh string subroutine syntax table terminal text threading time tkinter tutorial ubuntu unicode unsignedlong urllib urllib2 variable vb.net vba voip web-scrape whileloop word write wxpython






