目录
一、os库:提供操作系统交互功能
1.路径操作
import os
os.path.abspath('f.txt') #获取绝对路径(IDLE所在文件搜索)
'D:\\python310\\f.txt'
os.path.realpath('D:\\python310\\f.txt') #获取相对于IDLE的相对路径
'D:\\python310\\f.txt'
os.path.dirname('D:\\python310\\f.txt') #目录名
'D:\\python310'
os.path.basename('D:\\python310') #文件名
'python310'
os.path.exists('D:\\python310\\f.txt') #文件存在吗?
False
os.path.isfile('D:\\python310\\f.txt') #文件已经存在吗?
False
os.path.isfile("NEWS.txt")
True
os.path.getatime("NEWS.txt") #最近打开文件时间
1649974535.5738711
os.path.getmtime("NEWS.txt") #最近修改文件时间
1633346018.0
os.path.getctime("NEWS.txt") #创建文件时间
1633346018.0
import time
time.ctime(os.path.getctime("NEWS.txt"))
'Mon Oct 4 19:13:38 2021'
os.path