Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have been trying to list all the field names of a shapefile but it is showing 'expected an indented block'. What should I do?

import arcpy

fieldList = arcpy.ListFields("C:\Users\Mridul\Documents\GIS\Spring 2011\650\streets_dev.shp") 

for field in fieldList: 
print field.name + " is a type of " + field.type + " with a legth of " + field.length

rows = arcpy.UpdateCursor("C:\Users\Mridul\Documents\GIS\Spring 2011\650\streets_dev.shp", "SHAPE_len>400")  

cnt = 0

for row in rows: 
    row.STREETNAME = "OLD " + row.STREETNAME 
    rows.updateRow(row)
    cnt +=  1
    print cnt

del row 
del rows
share|improve this question

2 Answers 2

Your first for loop is missing an indented block.

for field in fieldList: #<----- The next line should be indented
print field.name + " is a type of " + field.type + " with a legth of " + field.length

Like this:

for field in fieldList:
    print field.name + " is a type of " + field.type + " with a legth of " + field.length

Or if the for loop only has a single statement, you can put on the same line.

for field in fieldList: print field.name

Python uses indentation to group statements. For more info, see the python reference.

share|improve this answer

Also note that this line:

fieldList = arcpy.ListFields("C:\Users\Mridul\Documents\GIS\Spring 2011\650\streets_dev.shp") 

will not work unless you use "raw" notation, i.e.

fieldList = arcpy.ListFields(r"C:\Users\Mridul\Documents\GIS\Spring 2011\650\streets_dev.shp") 

or replace the backslashes with forward slashes or double backslashes:

fieldList = arcpy.ListFields("C:\\Users\\Mridul\\Documents\\GIS\\Spring 2011\\650\\streets_dev.shp") 

fieldList = arcpy.ListFields("C:/Users/Mridul/Documents/GIS/Spring 2011/650/streets_dev.shp") 

or more cleverly use:

fieldList = arcpy.ListFields("C:\Users\Mridul\Documents\GIS\Spring 2011\650\streets_dev.shp".replace("\\","/") ) 
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.