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.
  File "C:\Python25\lib\site-packages\xlwt\", line 634, in save, self.get_biff_data())
  File "C:\Python25\lib\site-packages\xlwt\", line 609, in get_biff_data
    shared_str_table   = self.__sst_rec()
  File "C:\Python25\lib\site-packages\xlwt\", line 571, in __sst_rec
    return self.__sst.get_biff_record()
  File "C:\Python25\Lib\site-packages\xlwt\", line 53, in get_biff_record
  File "C:\Python25\Lib\site-packages\xlwt\", line 66, in _add_to_sst
    u_str = upack2(s, self.encoding)
  File "C:\Python25\Lib\site-packages\xlwt\", 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

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 -

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.