[Tutor] Unusual pathfile
Alan Gauld
alan.gauld at btinternet.com
Mon Sep 12 21:05:27 CEST 2011
On 12/09/11 15:49, Susana Iraiis Delgado Rodriguez wrote:
> Hi!
> I developed a python gui module to make a walk through a directory. This
> time I want the user to select the parameters I need from the python
> gui. The results will be written in a csv file, the problem I found is
> the pathfile shows this way:
> C:/\Archivos de programa\FWTools2.4.7\bin\mapnik-0.7.1\demo\data
What exactly do you feel is wrong with that?
Is it the fact that the first slash after the colon is forward facing?
Or is there something else?
> I'm workin with Python 2.6.6 and Windows XP, the code is:
Could you please use a few more spaces. Both to indent the code (2
spaces ids really the minimum and 3 or 4 is normal. But one is
useless) and to separate the functions vertically. (ie a blank line
before the def statements)
It is really very hard work wading through this stuff! I don't know how
you can read it but I'm struggling to see the structure.
> from Tkinter import * #Llamo las librerias graficas de Tk
> import tkSimpleDialog #Libreria de almacenamiento de dialogos
> import tkMessageBox #Libreria de mensajes
> import tkFileDialog
> import sys, os, csv, time, socket, stat
> from osgeo import ogr,gdal,osr
> from osgeo.gdalconst import *
> from PIL import Image
> dir = ""
> extn = ""
> csv_name = ""
> def directorio():
> global dir
> print 'Seleccione directorio donde empezar'
> dirname =
> tkFileDialog.askdirectory(parent=root,initialdir="/",title='Selecciona
> la ruta a escanear')
> if len(dirname ) > 0:
> print "You chose %s" % dirname
> dir = dirname
> def extension():
> global extn
> print "Escribe la extension que necesitas buscar"
> ext=tkSimpleDialog.askstring('Extension a buscar:','')
> print 'Buscando archivos: ',ext
> extn = ext
> def csv_w():
> global csv_name
> print "Nombre del csv a crear"
> inv=tkSimpleDialog.askstring('Nombre de .csv:','')
> print 'Archivo de salidad: ',inv
> csv_name = inv
> def boton4():
> print 'Iniciando...'
> gdal.AllRegister()
> file_list = []
> folders = None
> for root, folders, files in os.walk(dir):
> file_list.extend(os.path.join(root,fi) for fi in files if
> fi.endswith(extn))
> f = open(csv_name, 'wb')
> log = open ('log_errores.txt','w')
> writer = csv.writer(f)
> ruta = 'Ruta'
> archivo = 'archivo'
> x_min = 'x_min'
> x_max = 'x_max'
> y_min = 'y_min'
> y_max = 'y_max'
> geometria = 'geometria'
> num_elem = 'num_elem'
> prj = '.prj'
> proyeccion = 'proyeccion'
> fecha = 'fecha_modificacion'
> creacion = 'fecha_creacion'
> ultimo = 'ultimo_acceso'
> tamanio = 'tamanio_aprox'
> maq = 'maquina_host'
> usu = 'usuario'
> campos =
> [ruta,archivo,x_min,x_max,y_min,y_max,geometria,num_elem,prj,proyeccion,creacion,fecha,ultimo,tamanio,maq,usu]
> writer.writerow(campos)
> for row, filepath in enumerate(file_list, start=1):
> directorio = os.path.dirname(filepath)
> filename = os.path.basename(filepath)
> shapeData = ogr.Open(filepath)
> shp = 'Error al abrir el archivo' +filepath
> if shapeData is None:
> print shp
> log.write(shp+"\n")
> I don't want to get filepath order
I don't understand what that means?
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
More information about the Tutor
mailing list