Python-import导入上级目录文件同级文件夹

from pathlib import Path

FILE = Path(__file__).resolve()
ROOT = FILE.parents[0]#.parents[0]  #  root directory
#print(ROOT)

if str(ROOT) not in sys.path:
    sys.path.append(str(ROOT))  # add ROOT to PATH
ROOT = Path(os.path.relpath(ROOT, Path.cwd()))  # relative
ROOT = os.getcwd()
if str(ROOT) not in sys.path:
    sys.path.append(str(ROOT))
FILE = Path(__file__).resolve()
ROOT = FILE.parents[0].parents[0]  # root directory
#print(ROOT)

if str(ROOT) not in sys.path:
    sys.path.append(str(ROOT))  # add ROOT to PATH

你可能感兴趣的:(python,学习)