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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


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?
You've got a dictionary of dictionaries.  Not an object with attributes.  You'd reference it like this:

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
lz7cjcAuthor Commented:
thank you
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.