[Tutor] Unusual pathfile

Susana Iraiis Delgado Rodriguez susana.delgado_s at utzmg.edu.mx
Mon Sep 12 16:49:25 CEST 2011


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
I'm workin with Python 2.6.6 and Windows XP, the code is:
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110912/9d4b5750/attachment.html>


More information about the Tutor mailing list