[Tutor] getting and using information dict objects

Dave Angel davea at davea.name
Sun Feb 24 04:04:06 CET 2013


On 02/23/2013 09:40 PM, Matthew Johnson wrote:
> For the sake of those who finds this thread -- the date / value pairs
> can be printed by the following:
>
> import fred
>
> fred.key(fredKey)
>
> gnpObvs = fred.observations('GNPCA')
>
> for i in range(1, len(gnpObvs['observations']['observation'])):
>      print gnpObvs['observations']['observation'][i]['date'],
> gnpObvs['observations']['observation'][i]['value']
>
> mj
>

So it's returning a dict of dicts of lists of dicts?

Perhaps this loop would read better (untested):

for  item in gnpObvs['observations']['observation']:
     print item['date'], item['value']





-- 
DaveA


More information about the Tutor mailing list