Re: [Tutor] 'function' object has no attribute 'writer'
Hello Petter!! Thank you for answer to my question. I apologize for the writing of my code, won't happen again. I added the lines you suggested me, and the script work fine. Than you!! Here's the code corrected and indented. 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 = "" filesystemencoding = sys.getfilesystemencoding() 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.encode(filesystemencoding)) shp = 'Error al abrir el archivo' +filepath .. 2011/9/5 Peter Otten <__pete...@web.de> > Susana Iraiis Delgado Rodriguez wrote: > > Susana, please use 4-space indents for your code samples. I've said it > before, but I think it's worthwhile repeating because it makes it much > easier to grasp the structure of a script at first sight. > > > 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 osgeo import ogr,gdal,osr > > > shapeData = ogr.Open(filepath) > > filepath is a unicode string, your library seems to expect byte strings. > Try converting it like so: > > import sys > filesystemencoding = sys.getfilesystemencoding() > #... > shapeData = ogr.Open(filepath.encode(filesystemencoding)) > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] how to sort the file out
HI, I have two files, one is reference file, another is waiting for adjust one, File 1: 1 C1 2 O1 3 C2 4 C3 5 H3 6 C7 7 O2 8 H22 9 C6 10 H61 11 C5 12 H5 13 C4 14 C8 15 C9 16 C10 17 O3 18 C11 19 C12 20 O4 21 C13 22 C14 23 C15 24 C20 25 H20 26 C16 27 H16 28 C17 29 H17 30 C18 31 O6 32 H62 33 C19 34 O5 35 C21 File 2: 3 H16 4 H5 6 H61 7 H17 9 H20 12 H3 13 C1 14 O1 15 C2 16 C3 17 C4 18 C5 19 C6 20 C7 21 C8 22 C9 23 C10 24 O3 25 C11 26 C12 27 O4 28 C13 29 C14 30 C15 31 C20 32 C19 33 C18 34 C17 35 C16 36 O5 37 C21 38 O6 39 H62 40 O2 41 H22 I wish the field 2 from file 2 arranged the same sequence as the field 2 of file 1. Thanks for any suggestions, I drove my minds into nuts already, three hours passed and I still failed to achieve this. -- Best Regards, lina ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how to sort the file out
Perhaps a little more information on what is going on and what the expected outcome is. In order for the tutors to be able to better help you as I am not sure what you expect to get from these two lists. IE there is no field 2 in file 2, so what should it be? Also what should happen to the rest of the file if I make field 2 of file 2 equal "01"? -- Jordan On 09/06/2011 09:46 PM, lina wrote: > HI, I have two files, one is reference file, another is waiting for adjust > one, > > File 1: > > 1 C1 > 2 O1 > 3 C2 > 4 C3 > 5 H3 > 6 C7 > 7 O2 > 8 H22 > 9 C6 > 10 H61 > 11 C5 > 12 H5 > 13 C4 > 14 C8 > 15 C9 > 16 C10 > 17 O3 > 18 C11 > 19 C12 > 20 O4 > 21 C13 > 22 C14 > 23 C15 > 24 C20 > 25 H20 > 26 C16 > 27 H16 > 28 C17 > 29 H17 > 30 C18 > 31 O6 > 32 H62 > 33 C19 > 34 O5 > 35 C21 > > File 2: > 3 H16 > 4 H5 > 6 H61 > 7 H17 > 9 H20 > 12 H3 > 13 C1 > 14 O1 > 15 C2 > 16 C3 > 17 C4 > 18 C5 > 19 C6 > 20 C7 > 21 C8 > 22 C9 > 23 C10 > 24 O3 > 25 C11 > 26 C12 > 27 O4 > 28 C13 > 29 C14 > 30 C15 > 31 C20 > 32 C19 > 33 C18 > 34 C17 > 35 C16 > 36 O5 > 37 C21 > 38 O6 > 39 H62 > 40 O2 > 41 H22 > > I wish the field 2 from file 2 arranged the same sequence as the field > 2 of file 1. > > Thanks for any suggestions, > > I drove my minds into nuts already, three hours passed and I still > failed to achieve this. > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how to sort the file out
I was assuming that the numbers were field 1, and the letter/number combinations were field 2. If I understand him correctly, he wants the lines in file 2 to be arranged such that the order of field two is the same as it is in file 1. In that case, you can do it with one sexy sort() call (and a little preprocessing to load the files), but I don't want to get all into explain and then realize he wants something totally different. So please show us with some smaller files (5 lines is fine) what exactly you want the result to be. Hugo On Wed, Sep 7, 2011 at 7:14 AM, Jordan wrote: > Perhaps a little more information on what is going on and what the > expected outcome is. In order for the tutors to be able to better help > you as I am not sure what you expect to get from these two lists. IE > there is no field 2 in file 2, so what should it be? Also what should > happen to the rest of the file if I make field 2 of file 2 equal "01"? > -- > Jordan > > On 09/06/2011 09:46 PM, lina wrote: >> HI, I have two files, one is reference file, another is waiting for adjust >> one, >> >> File 1: >> >> 1 C1 >> 2 O1 >> 3 C2 >> 4 C3 >> 5 H3 >> 6 C7 >> 7 O2 >> 8 H22 >> 9 C6 >> 10 H61 >> 11 C5 >> 12 H5 >> 13 C4 >> 14 C8 >> 15 C9 >> 16 C10 >> 17 O3 >> 18 C11 >> 19 C12 >> 20 O4 >> 21 C13 >> 22 C14 >> 23 C15 >> 24 C20 >> 25 H20 >> 26 C16 >> 27 H16 >> 28 C17 >> 29 H17 >> 30 C18 >> 31 O6 >> 32 H62 >> 33 C19 >> 34 O5 >> 35 C21 >> >> File 2: >> 3 H16 >> 4 H5 >> 6 H61 >> 7 H17 >> 9 H20 >> 12 H3 >> 13 C1 >> 14 O1 >> 15 C2 >> 16 C3 >> 17 C4 >> 18 C5 >> 19 C6 >> 20 C7 >> 21 C8 >> 22 C9 >> 23 C10 >> 24 O3 >> 25 C11 >> 26 C12 >> 27 O4 >> 28 C13 >> 29 C14 >> 30 C15 >> 31 C20 >> 32 C19 >> 33 C18 >> 34 C17 >> 35 C16 >> 36 O5 >> 37 C21 >> 38 O6 >> 39 H62 >> 40 O2 >> 41 H22 >> >> I wish the field 2 from file 2 arranged the same sequence as the field >> 2 of file 1. >> >> Thanks for any suggestions, >> >> I drove my minds into nuts already, three hours passed and I still >> failed to achieve this. >> > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how to sort the file out
I'm also slightly confused. Why does file one start at 1, but file 2 starts at 3. Why not just duplicate file2? Bodsda Sent from my BlackBerry® wireless device -Original Message- From: lina Sender: tutor-bounces+bodsda=googlemail@python.org Date: Wed, 7 Sep 2011 12:46:37 To: tutor Subject: [Tutor] how to sort the file out HI, I have two files, one is reference file, another is waiting for adjust one, File 1: 1 C1 2 O1 3 C2 4 C3 5 H3 6 C7 7 O2 8 H22 9 C6 10 H61 11 C5 12 H5 13 C4 14 C8 15 C9 16 C10 17 O3 18 C11 19 C12 20 O4 21 C13 22 C14 23 C15 24 C20 25 H20 26 C16 27 H16 28 C17 29 H17 30 C18 31 O6 32 H62 33 C19 34 O5 35 C21 File 2: 3 H16 4 H5 6 H61 7 H17 9 H20 12 H3 13 C1 14 O1 15 C2 16 C3 17 C4 18 C5 19 C6 20 C7 21 C8 22 C9 23 C10 24 O3 25 C11 26 C12 27 O4 28 C13 29 C14 30 C15 31 C20 32 C19 33 C18 34 C17 35 C16 36 O5 37 C21 38 O6 39 H62 40 O2 41 H22 I wish the field 2 from file 2 arranged the same sequence as the field 2 of file 1. Thanks for any suggestions, I drove my minds into nuts already, three hours passed and I still failed to achieve this. -- Best Regards, lina ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how to sort the file out
For file 1, 1 C1 2 O1 3 C2 4 C3 5 H3 This one is much more like dictionary, ; nr atom cgnr charge mass 1 C1 10.062 15.0350 2 O1 1 -0.139 15.9994 3 C2 10.064 12.0110 4 C3 1 -0.001 12.0110 5 H3 10.014 1.0080 which was from field one and filed 2, namely the atom column, while for file 2: 12 H3 13 C1 14 O1 15 C2 16 C3 I want to be arranged like: 13 C1 14 O1 15 C2 16 C3 12 H3 only sort field 2 based on the dictionary, to match the sequence of C1, O1, C2, C3, H3. Thanks again, I want to arranged the field 3 according to match the dictionary (file 1) sequence. On Wed, Sep 7, 2011 at 1:52 PM, wrote: > I'm also slightly confused. Why does file one start at 1, but file 2 starts > at 3. Why not just duplicate file2? > > Bodsda > Sent from my BlackBerry® wireless device > > -Original Message- > From: lina > Sender: tutor-bounces+bodsda=googlemail@python.org > Date: Wed, 7 Sep 2011 12:46:37 > To: tutor > Subject: [Tutor] how to sort the file out > > HI, I have two files, one is reference file, another is waiting for adjust > one, > > File 1: > > 1 C1 > 2 O1 > 3 C2 > 4 C3 > 5 H3 > 6 C7 > 7 O2 > 8 H22 > 9 C6 > 10 H61 > 11 C5 > 12 H5 > 13 C4 > 14 C8 > 15 C9 > 16 C10 > 17 O3 > 18 C11 > 19 C12 > 20 O4 > 21 C13 > 22 C14 > 23 C15 > 24 C20 > 25 H20 > 26 C16 > 27 H16 > 28 C17 > 29 H17 > 30 C18 > 31 O6 > 32 H62 > 33 C19 > 34 O5 > 35 C21 > > File 2: > 3 H16 > 4 H5 > 6 H61 > 7 H17 > 9 H20 > 12 H3 > 13 C1 > 14 O1 > 15 C2 > 16 C3 > 17 C4 > 18 C5 > 19 C6 > 20 C7 > 21 C8 > 22 C9 > 23 C10 > 24 O3 > 25 C11 > 26 C12 > 27 O4 > 28 C13 > 29 C14 > 30 C15 > 31 C20 > 32 C19 > 33 C18 > 34 C17 > 35 C16 > 36 O5 > 37 C21 > 38 O6 > 39 H62 > 40 O2 > 41 H22 > > I wish the field 2 from file 2 arranged the same sequence as the field > 2 of file 1. > > Thanks for any suggestions, > > I drove my minds into nuts already, three hours passed and I still > failed to achieve this. > > -- > Best Regards, > > lina > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > -- Best Regards, lina ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Fwd: how to sort the file out
forgot to forward this to list, sorry. -- Forwarded message -- From: Hugo Arts Date: Wed, Sep 7, 2011 at 8:24 AM Subject: Re: [Tutor] how to sort the file out To: lina On Wed, Sep 7, 2011 at 8:16 AM, lina wrote: > On Wed, Sep 7, 2011 at 1:28 PM, Hugo Arts wrote: >> I was assuming that the numbers were field 1, and the letter/number >> combinations were field 2. If I understand him correctly, he wants the > > Yes. > >> lines in file 2 to be arranged such that the order of field two is the >> same as it is in file 1. In that case, you can do it with one sexy >> sort() call (and a little preprocessing to load the files), but I >> don't want to get all into explain and then realize he wants something >> totally different. > You understand right. > Well, it is fairly simple. You grab field2 from file1, and put all the items into a list (should be easy right? open(), readlines(), split(), grab second item). Then, you grab file2 as a list of tuples (same procedure as the first file, but you just put the results of split() right into the list. Then you sort with a key like so: list2.sort(key=lambda x: list1.index(x[1])) You see? For each item in the second list, we grab field 2, and look up what index it has in list1. Then we use that index as the sort key. That way they'll be sorted like file1 is. After that it's just a matter of writing back to the file, easy peasy. HTH, Hugo ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor