[Tutor] If statement isn't working

Susana Iraiis Delgado Rodriguez susana.delgado_s at utzmg.edu.mx
Fri Oct 29 18:49:11 CEST 2010

Hello members:

I'm trying to validate the existence of a file by an if statement, but it
isn't working correctly. The module is a crawler that writes to excel some
attributes from the files it finds.

folders = None
 # look in this (root) folder for files with specified extension
for root, folders, files in os.walk( "C:\\" ):
       file_list.extend(os.path.join(root,fi) for fi in files if
wrkbk = Workbook()
 #Add named parameter to allow overwriting cells: cell_overwrite_ok=True
wksht = wrkbk.add_sheet('shp')
#... add the headings to the columns
#write the rows
for row, filepath in enumerate(file_list, start=1):
  wksht.row(row).write(0, filepath)
 (ruta, filename) = os.path.split(filepath)
 wksht.row(row).write(1, filename)

#Here I`m splitting the string filename in base and extension
n = os.path.splitext(filename)
#Getting the base and prj as its extension
 p = n[0]+'.prj'
#validate if p exists
 if os.path.lexists(p):
  wksht.row(row).write(9, 1)
  prj_text = open(p, 'r').read()
  wksht.row(row).write(9, 0)
  wksht.row(row).write(8, 'Sin prj, no se puede determinar la proyeccion')

The issue is that it just identifies 3 prj and I have more, befores I
added  prj_text = open(p, 'r').read()
  wksht.row(row).write(8,prj_text) it worked fine and write the correct prj,
but now it doesn't

What am I doing wrong? Hope you can help me
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20101029/57a3569d/attachment.html>

More information about the Tutor mailing list