标准库

#!/usr/bin/env python 
# -*- coding:utf-8 -*-
# --------------*--------------
# @Author   : AilF
# @Time     : 2019/8/22 21:50
# @File     : pathFile.py
# @Software : PyCharm
# --------------*--------------


import os


current_path = os.getcwd()
print("当前文件的绝对路径为:" + current_path + "\" + str(os.path.abspath(__file__)).split('\')[-1])
print("****获取上层目录****")
print(os.path.abspath(os.path.dirname(__file__)))
print("****获取上上层目录****")
print(os.path.abspath(os.path.dirname(os.path.dirname(__file__))))
print("当前路径下的文件有:" + str(os.listdir(current_path)))
原文地址:https://www.cnblogs.com/longmin/p/11398124.html