| | |
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: 10
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
Views: 846 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for excel, python, unicode, xlwt
abrupt address advice ajax aliased arax asp avogadro beginner bluetooth c# c++ calling client code compile corners cturtle curves data dataanalysis dataset def dictionary django edit editing enter equipt examples excel file ftp function gui html http ideas iframe images import infiniteloop input itunes java linux list lists looping maze microsoft mouse movingimageswithpygame mysql mysqldb opensource parameters path ppc prime print programming projects push py2exe pygame pyglet pyqt python random recursive redirect remote ruby singleton smtp socket software string sum syntax table tennis text threading tkinter tooltip tutorial ubuntu unicode urllib urllib2 variable vb.net vba ventrilo wikipedia wordgame wxpython xlwt






