1
我有我的代碼在這裏這樣的,我想更新列表內的一些項目:更新Python字典元素給人以[]
coordinates = mongo_query.get_items({})
for json in coordinates:
json["person"] = "test"
json["location"] = "test"
for j in range(0, len(json["types"])):
json["types"][j] = "test"
new_coordinates = coordinates
這裏的時候,我調試變量new_coordinates是空的是這樣的:'[]'
座標的結果,如果我這樣做json_util.dumps(coordinates)
它給出了這樣的:
coordinates= [{"name": "my name", "timestamp": {"$date": 1459002562091}, "longitude": 20.169550966746304, "location": "Work", "victim": {"language": "English", "locality": "Bern", "gender": "Other", "region": "Gabon", "birthday": {"$date": 506736000000}, "nationality": "United States", "ethnicity": "Bosnian"}, "person": "Stranger", "latitude": 43.05529651674635, "personGender": "Male", "types": ["Shouting"]}, {"name": "my name", "timestamp": {"$date": 1455632962091}, "longitude": 21.292620354706038, "location": "Public Space", "victim": {"language": "English", "locality": "Ferizaj", "gender": "Other", "region": "Kosovo", "birthday": {"$date": 601516800000}, "nationality": "Canada", "ethnicity": "Turkish"}, "person": "Waiter", "latitude": 42.81558228232729, "personGender": "Male", "types": ["Comments", "Whistling"]}]
爲什麼會這樣,我不明白爲什麼我不能更新Ë在座標列表上放置什麼,以及它爲什麼會給出一個空列表?有人能幫助我嗎?
編輯:
所以看到的座標更好地在這裏:Jsonblob link
你介意漂亮的印刷'coordinates'?目前閱讀有點奇怪。 – erip
@erip請檢查我所做的修改,我添加了一個jsonblob鏈接,以便您可以更好地看到它? – EgzEst
是的,謝謝。 – erip