import json _keyfile = json.load(open("s3_key.json", "r"))
如果对它调用.read()呢?
import json _keyfile = json.loads(open("s3_key.json", "r").read())
根据 python docs ,文件将保持打开状态,直到调用 close() 在文件对象上 或 垃圾收集器为您启动并关闭它。
close()
with 语句)读取文件时,因为它们将为您关闭文件。
with
import json with open("s3_key.json", "r") as f: _keyfile = json.load(f) # f is now closed