Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #28693
| Date | 2012-09-07 17:47 +0200 |
|---|---|
| From | Jean-Michel Pichavant <jeanmichel@sequans.com> |
| Subject | Re: Defining features in a list |
| References | <e7c07576-677f-4230-9abc-34693e68fa7b@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.358.1347032919.27098.python-list@python.org> (permalink) |
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
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Defining features in a list M Whitman <mgwhitman@gmail.com> - 2012-09-07 06:42 -0700
Re: Defining features in a list Dave Angel <d@davea.name> - 2012-09-07 10:35 -0400
Re: Defining features in a list M Whitman <mgwhitman@gmail.com> - 2012-09-07 08:21 -0700
Re: Defining features in a list Dave Angel <d@davea.name> - 2012-09-07 11:55 -0400
Re: Defining features in a list Jean-Michel Pichavant <jeanmichel@sequans.com> - 2012-09-07 17:47 +0200
Re: Defining features in a list Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-09-07 15:29 -0400
csiph-web