[Tutor] Unpack requires a string argument of length 8

Susana Iraiis Delgado Rodriguez susana.delgado_s at utzmg.edu.mx
Fri May 6 16:29:57 CEST 2011

Hello Marc and Jim!

First of all, thanks to both of you!

I already changed the code, I added the try statement and the script runned
without ponting to an error. But now, I have another problem, even though,
it doesn't show an error message and makes the txt files, the files don't
have any lines written.

Before I added the try/catch lines, it showed the error, made the files and
writted them. I really need those txt files.

What did I do wrong?

import os,fnmatch
from osgeo import ogr,gdal,osr
from dbf import *
file_list = []
folders = None
for root, folders, files in os.walk( "C:\\" ):
    for filename in fnmatch.filter(files, '*.shp'):
        file_list.append(os.path.join(root, filename))
for row, filepath in enumerate(file_list, start=1):
    (ruta, filename) = os.path.split(filepath)
    shapeData = ogr.Open(filepath)
    if shapeData is None:
        print 'Error al abrir el archivo' +filepath
        n = os.path.splitext(filepath)
        f = os.path.splitext(filename)
        b = f[0]+'_bd.txt'
        d = n[0]+'.dbf'
        if os.path.lexists(d):
            filepath1 = "C:\\Python26\\dbf\\"
            a = open (filepath1 +b,"w+")
                Dbf(d,new=False, readOnly=True)
                for fldName in dbf.fieldDefs:
                    a.write(" || ")
                print n
                print 'El archivo ' +filepath+ ' esta vacio'
            print "El archivo " +n[0]+".shp" " no tiene dbf"
print "Listo"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110506/a18e09e7/attachment.html>

More information about the Tutor mailing list