variables - Getting specific information from raw information in python -


firstly sorry how badly question phrased not 100% sure how explain looking for. using geopy package in python.

basically use following code:

geolocator = nominatim() location = geolocator.reverse("{}, {}".format(lat, lon)) print(location.address) print((location.latitude, location.longitude)) print(location.raw) 

an example of output gives me is:

coastal track, totaranui, tasman, new zealand/aotearoa  (-40.8274559, 173.0053319)  {u'display_name': u'coastal track, totaranui, tasman, new zealand/aotearoa', u'place_id': u'93390086', u'lon': u'173.0053319', u'osm_type': u'way', u'licence': u'data \xa9 openstreetmap contributors, odbl 1.0. http://www.openstreetmap.org/copyright', u'osm_id': u'149082205', u'lat': u'-40.8274559', u'address': {u'path': u'coastal track', u'state': u'tasman', u'country': u'new zealand/aotearoa', u'country_code': u'nz', u'hamlet': u'totaranui'}} 

what want take things osm_id, osm_type etc , create variable them. tried location.raw.attrib['osm_type'] not work. new python appreciate , hope clear enough asking, thanks!

what you're looking calling key-value pairs dictionaries. want, osm_id , osm_type in variables, this:

osmid = location['osm_id'] 

you call part of dictionary want name of dictionary (location) , name of key want value of. then, store in osmid.


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -