unicode encoding in script

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jun 2009
Posts: 3
Reputation: somekid413 is an unknown quantity at this point 
Solved Threads: 0
somekid413 somekid413 is offline Offline
Newbie Poster

unicode encoding in script

 
0
  #1
Sep 16th, 2009
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.

  1. workBook.save((self.output))
  2. File "C:\Python25\lib\site-packages\xlwt\Workbook.py", line 634, in save
  3. doc.save(filename, self.get_biff_data())
  4. File "C:\Python25\lib\site-packages\xlwt\Workbook.py", line 609, in get_biff_data
  5. shared_str_table = self.__sst_rec()
  6. File "C:\Python25\lib\site-packages\xlwt\Workbook.py", line 571, in __sst_rec
  7. return self.__sst.get_biff_record()
  8. File "C:\Python25\Lib\site-packages\xlwt\BIFFRecords.py", line 53, in get_biff_record
  9. self._add_to_sst(s)
  10. File "C:\Python25\Lib\site-packages\xlwt\BIFFRecords.py", line 66, in _add_to_sst
  11. u_str = upack2(s, self.encoding)
  12. File "C:\Python25\Lib\site-packages\xlwt\UnicodeUtils.py", line 50, in upack2
  13. us = unicode(s, encoding)
  14. UnicodeDecodeError: 'ascii' codec can't decode byte 0xb1 in position 59: ordinal not in range(128)
  15.  

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
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 8
Reputation: god0fgod is an unknown quantity at this point 
Solved Threads: 0
god0fgod god0fgod is offline Offline
Newbie Poster

Re: unicode encoding in script

 
0
  #2
Sep 16th, 2009
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/
Last edited by god0fgod; Sep 16th, 2009 at 6:27 pm.
Reply With Quote Quick reply to this message  
Reply

Tags
excel, python, unicode, xlwt

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC