Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.006 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'output': 0.04; 'sys,': 0.07; 'nameerror:': 0.09; 'subject:features': 0.09; 'cc:addr :python-list': 0.10; '#test': 0.16; 'statement.': 0.16; 'xlrd': 0.16; 'wrote:': 0.17; 'basically': 0.17; 'thanks,': 0.18; 'define': 0.20; 'skip:" 30': 0.20; 'trying': 0.21; 'import': 0.21; 'os,': 0.22; 'defined': 0.22; 'cheers,': 0.23; 'cc:2**0': 0.23; "i've": 0.23; 'cc:no real name:2**0': 0.24; 'feature': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header :User-Agent:1': 0.26; 'appreciated.': 0.26; '(most': 0.27; 'errors.': 0.27; 'transition': 0.27; 'subject:list': 0.28; "i'm": 0.29; 'window': 0.30; 'lists': 0.31; 'file': 0.32; 'running': 0.32; 'print': 0.32; 'skip:s 30': 0.33; 'traceback': 0.33; 'code:': 0.33; 'excel': 0.33; 'skip:d 20': 0.34; 'text': 0.34; 'list': 0.35; 'similar': 0.35; 'something': 0.35; 'but': 0.36; 'does': 0.37; 'subject:: ': 0.38; 'sure': 0.38; 'advice': 0.39; 'skip:" 10': 0.40; 'received:194': 0.61; 'submission': 0.61; 'close': 0.63; 'for:': 0.64; 'online': 0.70; 'press': 0.71; 'everything,': 0.84 X-IronPort-AV: E=Sophos;i="4.80,387,1344204000"; d="scan'208";a="709400" X-Virus-Scanned: amavisd-new at zimbra.sequans.com Date: Fri, 07 Sep 2012 17:47:28 +0200 From: Jean-Michel Pichavant User-Agent: Mozilla-Thunderbird 2.0.0.24 (X11/20100328) MIME-Version: 1.0 To: M Whitman Subject: Re: Defining features in a list References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 76 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1347032919 news.xs4all.nl 6973 [2001:888:2000:d::a6]:55150 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:28693 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 > 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