import os
import sys
print(__file__) #获取当前相对 路径
print(os.path.abspath(__file__)) #动态获取绝对路径
print(os.path.dirname(os.path.abspath(__file__)))
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
#sys.path.append(BASE_DIR)#添加环境变量
#import conf,core
# from conf import setting
# from conf import main
读取json文件:
import json
import os
import sys
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
s1 = '\\'
file_lo = s1.join((BASE_DIR,"db","accounts","abc.json"))
with open(file_lo,'r') as f:
json_str = json.loads(f.read())
print(json_str)
输出为:
{'status': 0, 'password': 'abc', 'pay_day': 22, 'balance': 15974}