python 获取当前文件的父路径
示例
在from subpackage1.module1 import 包名之前需要获取当前文件的父路径:
import sys
import os
# Get the parent directory of the current file
parent_dir = os.path.abspath(os.path.join(os.getcwd(), "."))
# Append the parent directory to sys.path, otherwise the following import will fail
sys.path.append(parent_dir)
#from subpackage1.module1 import 包名