errors

1045
4
Jump to solution
03-21-2020 08:00 AM
CNRFGN
by
New Contributor II

i have found some errors but im sure not everything. what errors can you see in these?

import arcpy

from arcpy import env

env.workspace = "C:/EsriPress/Python/Data/Exercise07"

FC = "airports.shp" rows = arcpy.SearchCursor(fc)

fields = arcpy.ListFields(fc)

for field in fields:

if fields.name == "NAME"

for row in rows:

print "Name = {0}".format(row.getValue(field.name))

import arcpy

from arcpy import env

env.workspace = "C:/EsriPress/Python/Data\Exercise09"

raster = "landcover.tiff"

desc = arcpy.describe(raster)

x = desc.MeanCellHeight

y = desc.MeanCellWidth

spatialref = desc.spatialReference

units = spatialref.linearUnitName

print "Cells are" + str(x) + " by " + str(y) + " " + units + "."

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
DavidPike
MVP Frequent Contributor
import arcpy
#from arcpy import env
#i prefer to be explicit in module use

#use raw formatting
arcpy.env.workspace = r"C:/EsriPress/Python/Data/Exercise07"

#lower case
#is this in the workspace? if not use a full path
fc = "airports.shp" 

#arcpy.da.searchcursor is best
#rows = arcpy.SearchCursor(fc)
#fields = arcpy.ListFields(fc)
#for field in fields:
#if fields.name == "NAME"
#for row in rows:
#print "Name = {0}".format(row.getValue(field.name))

try:
    with arcpy.da.SearchCusor(fc, "NAME") as cursor:
        for row in cursor:
            print("Name = " + row)
except:
    print("No field 'NAME' found")
    break
 
 

View solution in original post

4 Replies
MichaelVolz
Esteemed Contributor

Try following steps in this link to present your code block:

https://community.esri.com/people/curtvprice/blog/2014/09/25/posting-code-blocks-in-the-new-geonet 

Can you also show the error messages that you are getting?

0 Kudos
CNRFGN
by
New Contributor II

its an exercise i didnt create these scripts.

0 Kudos
DanPatterson_Retired
MVP Emeritus

Show your results, someone else's samples aren't going to help if you don't have error messages.

0 Kudos
DavidPike
MVP Frequent Contributor
import arcpy
#from arcpy import env
#i prefer to be explicit in module use

#use raw formatting
arcpy.env.workspace = r"C:/EsriPress/Python/Data/Exercise07"

#lower case
#is this in the workspace? if not use a full path
fc = "airports.shp" 

#arcpy.da.searchcursor is best
#rows = arcpy.SearchCursor(fc)
#fields = arcpy.ListFields(fc)
#for field in fields:
#if fields.name == "NAME"
#for row in rows:
#print "Name = {0}".format(row.getValue(field.name))

try:
    with arcpy.da.SearchCusor(fc, "NAME") as cursor:
        for row in cursor:
            print("Name = " + row)
except:
    print("No field 'NAME' found")
    break