python调用不同目录下的方法

目录结构如下:

微信图片_20180927165357.png


atm.py调用main.py里的函数:

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()


猜你喜欢

转载自blog.51cto.com/fengxiaoli/2286737
今日推荐