Hello guys!!!
Shame on me, you're rigth I missunderstood the function and the module.
I change the name of my function and that part of my code worked.
But now I get a differente error, this script is going to collect
information from shapefiles, I asked the user where to start the search, the
file extension, and the csv name. Now I get:
>>> import win
>>> Seleccione directorio donde empezar
You chose C:/
Escribe la extension que necesitas buscar
Buscando archivos:  .shp
Nombre del csv a crear
Archivo de salidad:  gui.csv
Iniciando...
Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Python26\lib\lib-tk\Tkinter.py", line 1410, in __call__
    return self.func(*args)
  File "win.py", line 65, in boton4
    shapeData = ogr.Open(filepath)
  File "C:\Python26\lib\site-packages\osgeo\ogr.py", line 4033, in Open
    return _ogr.Open(*args, **kwargs)
TypeError: in method 'Open', argument 1 of type 'char const *'

The other part of 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")
2011/9/5 James Reynolds <eire1...@gmail.com>

>
>
>   On Mon, Sep 5, 2011 at 12:08 PM, Susana Iraiis Delgado Rodriguez <
> susana.delgad...@utzmg.edu.mx> wrote:
>
>>   I want to write a csv file, but I need the final user to give me some
>> values to open and update the file. My 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():
>>  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)
>> ....... more code
>> But when I run it,console shows:
>> Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 b
>> win32
>> Type "help", "copyright", "credits" or "license" for more informa
>> >>> import win
>> >>> Seleccione directorio donde empezar
>> You chose C:/
>> Escribe la extension que necesitas buscar
>> Buscando archivos:  .shp
>> Nombre del csv a crear
>> Archivo de salidad:  gui.csv
>> Iniciando...
>> Exception in Tkinter callback
>> Traceback (most recent call last):
>>   File "C:\Python26\lib\lib-tk\Tkinter.py", line 1410, in __call_
>>     return self.func(*args)
>>   File "win.py", line 43, in boton4
>>     writer = csv.writer(open(csv_name, 'w'))
>> AttributeError: 'function' object has no attribute 'writer'
>> I read a tutorial and csv has a writer function, I'm lost
>>
>> _______________________________________________
>> Tutor maillist  -  Tutor@python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>
>>
>
>
> You have a function called "csv()" in your code.
>
> So when you go csv.blahbittyblob, you've overriden your imported module
> called "csv" with the function called "csv", python then tries to look up
> the attribute blahbittyblob and can't find it. it then throws an error.
>
> Change your csv function to be csvx() or _csv or something other than csv
>
>
>
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to