sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))+'\\XXX')
說明:
__file__: 當前運行文件
os.path.abspath(__file__): 當前運行文件的絕對路徑
os.path.dirname(os.path.abspath(__file__)): 當前運行文件所在目錄的絕對路徑
os.path.dirname(os.path.dirname(os.path.abspath(__file__))):當前運行文件的上一級目錄的路徑
os.path.dirname(os.path.dirname(os.path.abspath(__file__)))+'\\XXX': 當前運行文件的上一級目錄中的XXX文件目錄或文件的路徑
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))+'\\XXX'):將當前運行文件的上一級目錄中的XXX文件目錄或文件的路徑填加到path
至此, 可以對XXX文件或目錄內的python文件和函數進行引用。