I'm a Python beginner and I would like to export a csv from a feature class, including only some fields. I'm trying to do it using the field mapping control, but I'm doing something wrong because I have the following error: RuntimeError: FieldMap: Error in adding input field to field map
here the code:
outPathTable = r"output_path" #get parameter as text
myFc = r'myFc_path' #get parameter as text
outName = myFc + "_dataQualityFc.csv"
List of fields to keep
outputFields = ['MemberID_target',
'PersonalID_target',
'Latitude',
'Longitude',
'dataQualityRisk_sameCH',
'dataQualityRisk_diffCH']
fieldMappings = arcpy.FieldMappings()
Create the field mappings from the outputField list
only fields in the list will be inlcuded in the exported file
for field in outputFields:
fieldMap = arcpy.FieldMap()
fieldMap.addInputField(myFc, field)
fieldMappings.addFieldMap(fieldMap)
Create a csv for Data Quality Risk using the field mapping
arcpy.TableToTable_conversion(myFc, outPathTable, outName, "", fieldMappings)