On 10/8/2010 12:34 PM Susana Iraiis Delgado Rodriguez said...
Hello members:
I developed a Python module to make a list which contains all the files
ending with .shp and .dbf extensions, I have solved this already, but now I
want to write an excel file from it. The file should show the full path from
the found files. This is the code:
import os
a = open ("directorio.xls","w")
allfiles = [] #store all files found
for root,dir,files in os.walk("C:\\"):
filelist = [ os.path.join(root,fi) for fi in files if
fi.endswith(".shp") or fi.endswith(".dbf") ]
for f in filelist:
allfiles.append(f)
for i in allfiles:
print i
a.write(i)
a.write("\n")
With the code above, I have the print and the .xls file with
this information in it, the issue here is that my file doesn't have the
complete information that I got in the console. Any idea? The last line from
excel is C:\Python26
You may find that finishing with a.flush() and a.close() fixes your problem.
Also, it appears that you're doing more than is required --
specifically, looping through filelist appending its members to allfiles
can be done more simply with append, so where you're saying:
filelist = [...
you could say
allfiles.extend([...
and forget about filelist entirely.
HTH,
Emile
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor