大家好,新年快樂!我是第一次在這里發帖,因為我找不到問題的答案,我已經搜索了 2 天,但不知道該怎么做,這讓我發瘋......這是我的問題:
我正在使用Steamspy api在Steam上下載過去 2 周內最常玩的 100 款游戲的資料,我可以將下載的資料轉儲到 .json 檔案(在本例中為 dumped_data.json),并匯入它回到我的 Python 代碼中(我可以列印它)。雖然我可以列印整個內容,但它并不是真的有用,因為它有 1900 行或多或少有用的資料,所以我希望能夠只列印轉儲資料的特定專案。在這個專案中,我只想列印串列中前 10 款游戲的名稱、開發商、所有者和價格。這是我的第一個 Python 專案,我不知道該怎么做……
這里的Python代碼:
import steamspypi
import json
#gets data using the steamspy api
data_request = dict()
data_request["request"] = "top100in2weeks"
#dumps the data into json file
steam_data = steamspypi.download(data_request)
with open("dumped_data.json", "w") as jsonfile:
json.dump(steam_data, jsonfile, indent=4)
#print values from dumped file
f = open("dumped_data.json")
data= json.load(f)
print(data)
這是 json 檔案中第一項的示例:
{
"570": {
"appid": 570,
"name": "Dota 2",
"developer": "Valve",
"publisher": "Valve",
"score_rank": "",
"positive": 1378093,
"negative": 267290,
"userscore": 0,
"owners": "100,000,000 .. 200,000,000",
"average_forever": 35763,
"average_2weeks": 1831,
"median_forever": 1079,
"median_2weeks": 1020,
"price": "0",
"initialprice": "0",
"discount": "0",
"ccu": 553462
},
提前感謝所有愿意幫助我的人,這將意味著很多。
uj5u.com熱心網友回復:
下面列印了您希望從前 10 場比賽中獲得的值:
for game in list(data.values())[:10]:
print(game["name"], game["developer"], game["owners"], game["price"])
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/400263.html
