我是python和一般編程的新手,請求幫助。如何在python中運行代碼來列印多個JSON檔案(300個檔案)中的資料,每個檔案的 "名稱 "行從#1改為#300,并且JSON檔案的名稱將從1.json到300.json。
這可能嗎?
{
"description": "#"/span>,
"image": "#",
"name": "#1",
"屬性": [
{
"trait_type": "#",
"value": "#", "value".
}
]
}
uj5u.com熱心網友回復:
試試這個:
# library to work with json stuff。
import json
# you can create dict first represent the json
json_dict = {
"description"。"#"。
"image": "#",
"name": "#1",
"屬性": [
{
"trait_type": "#",
"value": "#", "value".
}
]
}
# define numbers of file you want to create
n = 300
for i in range(1, n 1)。
# 改變每次迭代的 "name "屬性。
# 你可以使用f-string方法。
json_dict["name"] = f "#{i}"
# save the dict to file
# 再次,使用f-string來命名檔案。
with open(f"{i}.json", 'w') as json_file。
#json.dump() method save dict json to file[/span]。
json.dump(json_dict, json_file)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/322793.html
標籤:
上一篇:AdaptiveCards在.NET決議時拋出一個例外
下一篇:如何從JSON物件中獲取特定值
