python調用不一樣目錄下的方法

目錄結構以下: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()
相關文章
相關標籤/搜索