[Tutor] 'function' object has no attribute 'writer'
Susana Iraiis Delgado Rodriguez
susana.delgado_s at utzmg.edu.mx
Mon Sep 5 18:08:24 CEST 2011
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110905/951083f8/attachment.html>
More information about the Tutor
mailing list