Suspected Unicode problem when reading text from Excell

Ian Parker parker at gol.com
Thu Sep 6 04:54:22 EDT 2001


In article <3b9611ec$0$262$edfadb0f at dspool01.news.tele.dk>, maxm
<maxm at normik.dk> writes
>I have the following piece of code that sort of works ok.
>
>import win32com.client
>xl=win32com.client.Dispatch("Excel.Application")
>xl.Visible=1
>wb=xl.Workbooks(1)
>sh=wb.Worksheets(1)
>for row in sh.UsedRange.Value:
>    (type, question, options, answerText, beforePic,
>     afterPic, misc1, misc2, misc3, misc4) = row
>    print question, options, answerText
>
>But when I run it I get the error:
>
>  File "C:\div\uninstalled\python\excell\jensMarius.py", line 9, in ?
>    print question, options, answerText
>UnicodeError: ASCII encoding error: ordinal not in range(128)
>
>If i do this:
>
>
>

I encountered this, to my horror, a few weeks ago. My python script was
just about ready for the big-time, worked perfectly on the test data and
then bombed with this error when I ran it for real.  To my great relief
there was  a discussion about this topic at that time in c.l.p.   

You simply need to set your default encoding to "Latin-1", so that you
can handle the full range of 8-bit characters.  You have to do this
early on in Python initialisation:

In sitecustomize.py:
        encoding = 'latin-1'
        sys.setdefaultencoding(encoding,)

Regards

-- 
Ian Parker



More information about the Python-list mailing list