demo_dir.py
import os
"""获取当前目录"""
print(os.getcwd())
print(os.path.abspath(os.path.dirname(__file__)))
"""获取上一级目录"""
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(os.path.abspath(os.path.join(os.getcwd(), "../..")))
"""获取当前路径的文件夹以及路径"""
all_file = [f for f in os.listdir(os.getcwd())]
for all_ in all_file:
if os.path.isdir(all_):
print(all_)