LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-10-2015, 03:13 PM   #1
PoleStar
Member
 
Registered: Jul 2010
Posts: 184

Rep: Reputation: 2
python: return dict/sturcture. cant access attributes.


Code:
 Method: getRelevantErrata
Description:
Returns a list of all errata that are relevant to the system.

Parameters:

    string sessionKey
    int serverId

Returns:

    array:
        struct - errata
            int "id" - Errata ID.
            string "date" - Date erratum was created.
            string "update_date" - Date erratum was updated.
            string "advisory_synopsis" - Summary of the erratum.
            string "advisory_type" - Type label such as Security, Bug Fix
            string "advisory_name" - Name such as RHSA, etc
so brings back
Code:
[{'advisory_name': 'RHBA-1111:1111', 'update_date': '11/11/11', 'advisory_type': 'Bug Fix Advisory', 'date': '11/11/11', 'id': 1122, 'advisory_synopsis': 'kernel bug fix update'},
Using python, how could i get directly access one the element of this "structure" ?
Suppose I wanted only "advisory_name"

I did
Code:
ad = call_the_thing(111,xyz)
print ad
It printed:
Code:
[{'advisory_name': 'RHBA-1111:1111', 'update_date': '11/11/11', 'advisory_type': 'Bug Fix Advisory', 'date': '11/11/11', 'id': 1122, 'advisory_synopsis': 'kernel bug fix update'},
but when I try
print ad.date

it say dict object does not have attribute "date"

Please help.
 
Old 12-10-2015, 03:46 PM   #2
Myk267
Member
 
Registered: Apr 2012
Location: California
Posts: 420
Blog Entries: 16

Rep: Reputation: Disabled
It looks like a list (square brackets) in your return value, so you'll need to index into it somehow, then use the dict key to get the value out.

Something like...
Code:
ad = call_the_thing(111,xyz)
print(a[0]['date'])
Or you could get all of the dates...
Code:
ad = call_the_thing(111,xyz)
for i in ad:
    print(i['date'])
Hope this helps.

Last edited by Myk267; 12-10-2015 at 03:54 PM.
 
1 members found this post helpful.
Old 12-11-2015, 04:34 PM   #3
PoleStar
Member
 
Registered: Jul 2010
Posts: 184

Original Poster
Rep: Reputation: 2
Myk276 It worked
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Python dict query and assign values problems ArthurHuang Programming 2 03-13-2012 04:18 AM
[SOLVED] Python: How to get the return value of the last function? ryan858 Programming 2 06-14-2010 04:27 AM
Python and instance attributes clausawits Programming 2 12-08-2004 10:17 AM
Sturcture for RADIUS packet abdullahgee Programming 3 04-27-2004 08:18 AM
python: return not returning bulliver Programming 1 01-09-2003 06:48 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:46 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration