尝试读取json文件并以字典形式返回:
def js_r(filename):
with open('num.json', 'r')as f_in:
json_d = f_read()
Run Code Online (Sandbox Code Playgroud)
如何返回字典函数?
使用json
模块对其进行解码。
import json
def js_r(filename):
with open(filename) as f_in:
return(json.load(f_in))
if __name__ == "__main__":
my_data = js_r('num.json')
print(my_data)
Run Code Online (Sandbox Code Playgroud)