天天看点

python调用不同目录下的方法

目录结构如下:

python调用不同目录下的方法

import os
import sys
# print(__file__)                        #获取当前文件相对路径
#print(os.path.abspath(__file__))        #通过相对路径获取绝对路径
#print(os.path.dirname(os.path.abspath(__file__)))   #获取当前文件父目录
DIR_BASE = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# print(DIR_BASE)
sys.path.append(DIR_BASE)                 #将该路径追加到环境变量

from  conf import setting
from core import main

main.login()