import os
- print('获取当前目录')
- print(os.getcwd())
- print(os.path.abspath(os.path.dirname(file)))
-
- print('获取上级目录')
- print(os.path.abspath(os.path.dirname(os.path.dirname(file))))
- print(os.path.abspath(os.path.dirname(os.getcwd())))
- print(os.path.abspath(os.path.join(os.getcwd(), "..")))
-
- print('获取上上级目录')
- print(os.path.abspath(os.path.dirname(os.path.dirname(file))))
- print(os.path.abspath(os.path.join(os.getcwd(), "../..")))
原文地址:https://blog.csdn.net/qq_43178297/article/details/88053836