Printing out the contents of an object to an HTML page using Django

I have a library which i am trying to use but I don't know how to access parts of the returned object

The code I run in python is:
from boris import BikeChecker
from pprint import PrettyPrinter
bc = BikeChecker()
pp = PrettyPrinter()
bike_predicate = lambda x: x['nbBikes'] >= 2
nearest = bc.find_with_geo(51.49, -0.19, predicate=bike_predicate)

Open in new window

which outputs the following:
C:\Python27\python.exe C:/Users/nicka_000/Documents/Coding/websites_go_here/testing/
{'distance': 0.032766888603455446,
 'station': {'id': 219,
             'installDate': 1279545900000L,
             'installed': True,
             'lat': 51.49016361,
             'locked': False,
             'long': -0.19039362,
             'name': u"Bramham Gardens, Earl's Court",
             'nbBikes': 8,
             'nbDocks': 29,
             'nbEmptyDocks': 20,
             'removalDate': None,
             'temporary': False,
             'terminalName': u'001183'}}

Process finished with exit code 0
 what I  want to do is access the lat and long variables within that object and store for later use. How would I do that

thanks very much
Who is Participating?
You've got a dictionary of dictionaries.  Not an object with attributes.  You'd reference it like this:

Open in new window


setting the variable "nearest" to the JSON, you might access it as like

Open in new window

lz7cjcAuthor Commented:
thanks for the article but I still don't get it - sorry!

I tried and I get the following error:
AttributeError: 'dict' object has no attribute 'station'

So I did this:

import demjson
lat = demjson.decode(nearest)
print lat

Open in new window

where am I going wrong?
lz7cjcAuthor Commented:
thank you
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.