Pathlib简单应用
import os
# 获取上一层目录
print(os.path.dirname(os.getcwd())) # /Users/na/PycharmProjects/python_1test/a/c
# 获取上上层目录
print(os.path.dirname(os.path.dirname(os.getcwd()))) # /Users/na/PycharmProjects/python_1test
from pathlib import Path
# 获取上一层目录
print(Path.cwd().parent) # /Users/na/PycharmProjects/python_1test/a
# 获取上上层目录
print(Path.cwd().parent.parent) # /Users/na/PycharmProjects/python_1test
# 获取绝对路径-->目录
print(Path().cwd()) # /Users/na/PycharmProjects/python_1test/a/c
print(Path().resolve()) # /Users/na/PycharmProjects/python_1test/a/c
学习文档:https://blog.csdn.net/qq_43965708/article/details/122537713
标签:Users,python,na,Pathlib,学习,1test,PycharmProjects,print From: https://www.cnblogs.com/luonacx/p/17494571.html