[Tutor] Python and excel writer: 'ascii' codec can't decode byte 0xf3 in position 49

Susana Iraiis Delgado Rodriguez susana.delgado_s at utzmg.edu.mx
Mon Oct 25 17:10:32 CEST 2010


Hello members:

I'm starting an script for geospatial information using python and gdal
binaries, but I have problems saving the data I get into an excel shee. At
the beginning I thought it was because the characters the files have for
some records, but I run the code in a way it saves the path for each file
I'm looking for. The script throws th error:
Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)]
on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import imagen
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "imagen.py", line 20, in <module>
    wrkbk.save('imagen.xls')
  File "C:\Python26\lib\site-packages\xlwt\Workbook.py", line 634, in save
    doc.save(filename, self.get_biff_data())
  File "C:\Python26\lib\site-packages\xlwt\Workbook.py", line 609, in
get_biff_d
ata
    shared_str_table   = self.__sst_rec()
  File "C:\Python26\lib\site-packages\xlwt\Workbook.py", line 571, in
__sst_rec
    return self.__sst.get_biff_record()
  File "C:\Python26\lib\site-packages\xlwt\BIFFRecords.py", line 53, in
get_biff
_record
    self._add_to_sst(s)
  File "C:\Python26\lib\site-packages\xlwt\BIFFRecords.py", line 66, in
_add_to_
sst
    u_str = upack2(s, self.encoding)
  File "C:\Python26\lib\site-packages\xlwt\UnicodeUtils.py", line 50, in
upack2
    us = unicode(s, encoding)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xf3 in position 49:
ordinal
 not in range(128)
>>>
My code is:
import os, time, socket
from xlwt import Workbook
from osgeo import gdal
from osgeo.gdalconst import *
from PIL import Image

gdal.AllRegister()
file_list = []
folders = None
 # look in this (root) folder for files with specified extension
for root, folders, files in os.walk( "C:\\" ):
 file_list.extend(os.path.join(root,fi) for fi in files if
fi.endswith(".tif") or fi.endswith(".tiff") or fi.endswith(".gtif") or
fi.endswith(".ecw") or fi.endswith(".bil") or fi.endswith(".til") or
fi.endswith(".jpeg"))
wrkbk = Workbook()
wksht = wrkbk.add_sheet('rasters')
wksht.row(0).write(0,'ruta')
for row, filepath in enumerate(file_list, start=1):
 #Llenar lista de archivos y ruta
 wksht.row(row).write(0, filepath)
wrkbk.save('imagen.xls')

Is there a way I can manage this error?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20101025/5bc864ce/attachment.html>


More information about the Tutor mailing list