Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Python challenge: a- Create a custom function called countstringfields that dete

ID: 3762960 • Letter: P

Question

Python challenge:

a- Create a custom function called countstringfields that determines the number of fields of type string there are in an input feature class. Create this function in a separate script ( for example, mycount.py ) that you call from another script ( for example, callingscript.py ). You can use the streets.shp feature class in the Lab 10 folder.

b- You are given a feature class called parcels.shp located in Lab 10 folder that contains the following fields: FID, Shape, Landuse, and Value. Modify the parceltax.py script so that it determines the property tax for each parcel and stores these values in a list. You should use the class created in the parcelclass.py script above (the class can remain unchanged). Print the values of the final list by FID.

Explanation / Answer

import arcpy    

def numberStringFieldsWithLayer(layer = None)  

    # If no layer is passed in, stop the function  

    if layer == None:  

        return None    

    # Get the count for each field with type "String"  

    n = 0  

    for field in arcpy.ListFields(layer):  

        if field.type == "String":  

            n += 1   

    return n  

import sys  

sys.path.append(r"Path oyourcustommodule older")  

# import your custom moudle  

import customModule    

# Make a layer object from your feature layer  

streetsLayer = arcpy.mapping.Layer("streets")    

# Call you custom function from the module  

numberOfFieldsTypeString = customModule.numberStringFieldsWithLayer(streetsLyer)   

# Remove your layer reference  

del streetsLayer    

# Print your results  

print numberOfFieldsTypeString