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


Groups > comp.lang.python > #94437

Re: convert output to list(and nested dictionary)

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!bcyclone04.am1.xlned.com!bcyclone04.am1.xlned.com!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'skip:[ 20': 0.03; 'attributes': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'useful,': 0.13; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'wrote:': 0.16; 'attribute': 0.18; 'debugging': 0.18; 'names.': 0.22; 'object.': 0.22; 'parse': 0.22; 'header:User-Agent:1': 0.26; 'subject:list': 0.26; 'header:X-Complaints-To:1': 0.26; 'skip:" 20': 0.26; 'object,': 0.27; 'function': 0.28; 'actual': 0.28; 'purposes.': 0.29; 'strings,': 0.29; 'convert': 0.29; 'print': 0.30; 'probably': 0.31; 'skip:s 30': 0.31; 'getting': 0.33; 'class': 0.33; 'foo': 0.33; 'grants': 0.33; 'instances': 0.33; 'rule': 0.33; 'could': 0.35; 'dir': 0.35; 'but': 0.36; 'skip:i 20': 0.36; 'should': 0.36; 'instead': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'doing': 0.38; 'does': 0.39; 'to:addr:python.org': 0.40; 'received:de': 0.40; 'some': 0.40; 'peter,': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Peter Otten <__peter__@web.de>
Subject Re: convert output to list(and nested dictionary)
Date Thu, 23 Jul 2015 11:59:21 +0200
Organization None
References <CAKoJ+qB7mLX+tLAqsO=nSocjVLtLn+TCWZ34z8YVFCKKt10ntQ@mail.gmail.com> <CAB_tDZyB+mCg9yWg9oG0-OL-NHVfCSifkMrD0x3k4LPNx-dhNw@mail.gmail.com> <CAKoJ+qCzMetyyqC-2rg0KB2kmFdVeNkVj053OYeXn9meZ1FJxQ@mail.gmail.com> <CAKoJ+qDp5ii8o1L4ZvimMNyr5Bgm-DBnNy9E5XzB4r_oZY4Ngg@mail.gmail.com> <mookki$jrb$1@ger.gmane.org> <CAKoJ+qCPJ_37+YdUx4ox3f_DeDWtKEKh60++jf_=asVQW6vN1w@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding 7Bit
X-Gmane-NNTP-Posting-Host p57bd9370.dip0.t-ipconnect.de
User-Agent KNode/4.13.3
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.907.1437645573.3674.python-list@python.org> (permalink)
Lines 39
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1437645573 news.xs4all.nl 2946 [2001:888:2000:d::a6]:48058
X-Complaints-To abuse@xs4all.nl
X-Received-Bytes 4168
X-Received-Body-CRC 2671617854
Xref csiph.com comp.lang.python:94437

Show key headers only | View raw


max scalf wrote:

> Hi Peter,
> 
> Could you please explain what i am doing wrong?  I did inspected the
> "get_all_security_groups()" object using dir and i do need the get_data
> function for this to work...as i have to parse the output...just getting
> the rule and grants does not work...as it comes with extra verbiage that i
> do NOT need in my dictionary...see below...
> 
>>>> for sg in sgs:
>     for rule in sg.rules:
>         print sg, sg.id, rule, rule.grants
> 
> 
> SecurityGroup:wordpress-app-SG sg-99c4befc IPPermissions:-1(None-None)
> [sg-e632d982-995635159130]
...

It's not "extra verbiage", you print the whole sg object, and the author of 
the SecurityGroup class has chosen one way to convert SecurityGroup 
instances into strings, the one that he deems most useful, probably for 
debugging purposes.

But you are only interested in some attributes of the sg object. Instead of

print sg

you should only print

print sg.foo, sg.bar

foo and bar are fictitious attribute names, but you can find candiates for 
these attributes with

print dir(sg)

which will print the actual names.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: convert output to list(and nested dictionary) Peter Otten <__peter__@web.de> - 2015-07-23 11:59 +0200

csiph-web