Python常用方法库备忘(一)_当前路径下文件夹和文件

时间:2022-08-30 15:42:16
#!/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)))