[Tutor] Unpack requires a string argument of length 8
Alan Gauld
alan.gauld at btinternet.com
Fri May 6 19:20:23 CEST 2011
"Susana Iraiis Delgado Rodriguez" <susana.delgado_s at utzmg.edu.mx>
wrote
> I already changed the code, I added the try statement and the script
> runned
> without ponting to an error.
So to be clear. You run the script and it does NOT print
'El archivo ' +filepath+ ' esta vacio'
But your file could still be empty since
> if os.path.lexists(d):
> filepath1 = "C:\\Python26\\dbf\\"
> a = open (filepath1 +b,"w+")
> try:
> Dbf(d,new=False, readOnly=True)
> for fldName in dbf.fieldDefs:
Have you tried printing dbf.fieldDefs?
If that is empty then the following code will not run.
try/except is not a magic cure-all. It needs something
to trigger the exception, if you try to itertate over an
empty list that won't do it.
> a.write(fldName.name)
> a.write(" || ")
> a.write(fldName.typeCode)
> a.write("\n")
> dbf.close()
> a.close()
> print n
> except:
> print 'El archivo ' +filepath+ ' esta vacio'
You should probably change the except to catch specific
errors rather than be a catch-all, but I'm not sure which
errors you might catch. That depends on the Dbf class design.
> else:
> print "El archivo " +n[0]+".shp" " no tiene dbf"
> print "Listo"
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
More information about the Tutor
mailing list