我需要帮助将 .txt 输出文件的名称更改为 json 文件内的日期,这可能吗?
Json:
"date": "2018-03-21",
python :
import urllib.request, json
with urllib.request.urlopen("http://api.fixer.io/latest?&base=EUR") as url:
data=json.loads(url.read().decode())
print(data)
with open('*changeNameHere*{}.txt'.format(*Example*), 'w') as outfile:
json.dump(data["rates"], outfile)
最佳答案
简单地做:
import urllib.request, json
with urllib.request.urlopen("http://api.fixer.io/latest?&base=EUR") as url:
data=json.loads(url.read().decode())
print(data)
with open('{}.txt'.format(data['date']), 'w') as outfile:
json.dump(data["rates"], outfile)
关于python - Python中输出json txt名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49427867/