[Tutor] if os.path.exists() or if not os.path.exists()?

Susana Iraiis Delgado Rodriguez susana.delgado_s at utzmg.edu.mx
Thu Mar 24 22:01:21 CET 2011


OK!! I see the problem now!
I also did a little change to the code,  I open the .txt before the for
stamentet. The script is working properly
gdal.AllRegister()
file_list = [
folders = Non
for root, folders, files in os.walk( "C:\\" ):
   file_list.extend(os.path.join(
root,fi) for fi in files if
fi.endswith(".shp"))
f = open('csv_pruebita.csv', 'wb')
log = open ('errors.txt','wb')
writer = csv.writer(f)
ruta = 'Ruta'
archivo = 'archivo'
prj = '.prj'
proyeccion = 'proyeccion'
campos = [ruta,archivo,prj,proyeccion]
writer.writerow(campos)

for row, filepath in enumerate(file_list, start=1):
        #Partir la ruta del archivo en dos, ruta y nombre del archivo
        (ruta, filename) = os.path.split(filepath)
        #Escribir el nombre del archivo
        shapeData = ogr.Open(filepath)
        shp = 'Error al abrir el archivo' +filepath
        #Abrir archivo de errores
        if shapeData is None:
                print shp
                log.write(shp+"\n")
        #Obtener la capa del shape
        else:
......
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110324/4e610297/attachment.html>


More information about the Tutor mailing list