943,568 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Unsolved
  • Views: 2272
  • Python RSS
Sep 16th, 2009
0

unicode encoding in script

Expand Post »
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.

Python Syntax (Toggle Plain Text)
  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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
somekid413 is offline Offline
3 posts
since Jun 2009
Sep 16th, 2009
0

Re: unicode encoding in script

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
god0fgod is offline Offline
11 posts
since Oct 2008

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: Is Python a good choice?
Next Thread in Python Forum Timeline: How can webservice maintain session





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


Follow us on Twitter


© 2011 DaniWeb® LLC