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


Groups > comp.lang.python > #94437 > unrolled thread

Re: convert output to list(and nested dictionary)

Started byPeter Otten <__peter__@web.de>
First post2015-07-23 11:59 +0200
Last post2015-07-23 11:59 +0200
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#94437 — Re: convert output to list(and nested dictionary)

FromPeter Otten <__peter__@web.de>
Date2015-07-23 11:59 +0200
SubjectRe: convert output to list(and nested dictionary)
Message-ID<mailman.907.1437645573.3674.python-list@python.org>
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.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web