Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #28693

Re: Defining features in a list

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 <prvs=5903110a8=jeanmichel@sequans.com>
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 <jeanmichel@sequans.com>
User-Agent Mozilla-Thunderbird 2.0.0.24 (X11/20100328)
MIME-Version 1.0
To M Whitman <mgwhitman@gmail.com>
Subject Re: Defining features in a list
References <e7c07576-677f-4230-9abc-34693e68fa7b@googlegroups.com>
In-Reply-To <e7c07576-677f-4230-9abc-34693e68fa7b@googlegroups.com>
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 <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.358.1347032919.27098.python-list@python.org> (permalink)
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

Show key headers only | View raw


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 | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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