Defining features in a list
Jean-Michel Pichavant
jeanmichel at sequans.com
Fri Sep 7 11:47:28 EDT 2012
M Whitman wrote:
> Good Morning,
>
> I have been recently trying to define all of the features in a list but have been running into errors. I would like to define the features similar to the following print statement. Any advice would be appreciated. I'm trying to transition my output from a text file to excel and if I can loop through my lists and define them that transition will be cleaner.
>
> Many Thanks,
>
> -Matt
>
> #Author: MGW
> #2012
> import os, datetime, sys, arcpy, xlrd
> from arcpy import env
> submission = "Rev.mdb"
> env.workspace = "C:/temp/"+submission+"/Water"
>
> #Get Submission totals
> fclist = sorted(arcpy.ListFeatureClasses("*"))
> for fc in fclist:
> print fc+"="+str(arcpy.GetCount_management(fc).getOutput(0))
>
> print "Complete"
> raw_input("Press ENTER to close this window")
>
> Output Generated
> WATER_Net_Junctions=312
> WS_Hyd=484
> WS_Mains=2752
> WS_Node=4722
> WS_Vlvs=1078
> WS_WatLats=3661
> WS_WatMtrs=3662
> WTRPLANTS_points=0
> WTRPUMPSTA_points=0
> WTRTANKS=0
> WTR_ARV=10
> WTR_MISC=0
> Complete
> Press ENTER to close this window
>
> #Get Submission totals
> fclist = sorted(arcpy.ListFeatureClasses("*"))
> for fc in fclist:
> fc=str(arcpy.GetCount_management(fc).getOutput(0))
> #TEST
> print WS_Hyd
>
>
> print "Complete"
> raw_input("Press ENTER to close this window")
>
> Output Generated
> Traceback (most recent call last):
> File "C:\Documents and Settings\mattheww\Desktop\Copy of QAQCexce_2.py", line 14, in <module>
> print WS_Hyd
> NameError: name 'WS_Hyd' is not defined
>
I'm not sure I've understood everything, is this something you're
searching for:
fcDict = dict([(str(fc),
str(arcpy.GetCount_management(fc).getOutput(0))) ) for fc in
sorted(arcpy.ListFeatureClasses("*")) ])
print fcDict
print fcDict['WS_Hyd']
This is difficult to read because of the online statement, but it does
basically the following pseudo code:
fcDict = dict([(feature.name, feature.value) for feature in featureList ])
Cheers,
JM
More information about the Python-list
mailing list