2017-07-29 73 views
0

的Python 5.6包含嵌套元素

這裏遍歷一個字典對象正在使用的地理編碼器模塊

import geocoder 
anaddress = 'State Street, Hood River, OR' 
g = geocoder.arcgis(anaddress) 
d = g.geojson 
print(d) 
{'geometry': {'type': 'Point', 'coordinates': [-121.52181774656506, 45.707876183969184]}, 'type': 'Feature', 'properties': 
{'provider': 'arcgis', 'ok': True, 'location': '1037 State St, Hood River, OR', 'lat': 45.707876183969184, 'lng': -121.52 
181774656506, 'bbox': [-121.52281774656507, 45.706876183969186, -121.52081774656506, 45.70887618396918], 'encoding': 'utf- 
8', 'status': 'OK', 'address': '1037 State St, Hood River, Oregon, 97031', 'status_code': 200, 'confidence': 9}, 'bbox': [ 
-121.52281774656507, 45.706876183969186, -121.52081774656506, 45.70887618396918]} 

我如何能夠通過這種結構迭代並打印出來很好地從一個電話,結果呢?

+1

'from pprint import pprint; pprint(d)' – GWW

+1

5.6 ??也許3.6? – aristotll

回答

1

你的目標只是爲了打印結構還是解析它?

在你只想打印輸出很好的情況下,試試這個

from pprint import pprint 
pprint(d) 

這將爲您提供一個很好的印刷結構。 爲了解析這個,你可以像使用鍵和值一樣使用任何字典對象。

+0

這正是我想要的! – Vietyank