在当前项目下新建一个文件夹,把字典的json文件放入其中,比如你的json文件叫a.json
def load_config():
with open(os.path.dirname(os.path.abspath(__file__))+"/config/a.json".format(sys.path[0]), "rb") as f:
print("Load default config")
return json.load(f)
temp = load_config()
本文介绍了一种在Python中从特定目录加载JSON配置文件的方法。通过使用os和json模块,可以定位并读取位于项目根目录下config文件夹内的a.json文件。
在当前项目下新建一个文件夹,把字典的json文件放入其中,比如你的json文件叫a.json
def load_config():
with open(os.path.dirname(os.path.abspath(__file__))+"/config/a.json".format(sys.path[0]), "rb") as f:
print("Load default config")
return json.load(f)
temp = load_config()
3895
187
1144

被折叠的 条评论
为什么被折叠?