一、os库

目录操作

一、获取当前、上级、上上级目录
import os

print '***获取当前目录***'
print os.getcwd()
print os.path.abspath(os.path.dirname(__file__))

print '***获取上级目录***'
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 '***获取上上级目录***'
print os.path.abspath(os.path.join(os.getcwd(), "../.."))

二:进入目录
dir=os.getcwd()
os.chdir(dir+"\\data")

文件操作

判断文件是否存在

https://www.runoob.com/w3cnote/python-check-whether-a-file-exists.html

二、shutil库

https://blog.csdn.net/caribbean666/article/details/124928413

三、tempfile库 (临时文件)

https://www.jianshu.com/p/3cc7b9404dd0
https://blog.csdn.net/weixin_44799217/article/details/126454502


0 条评论

发表回复

您的电子邮箱地址不会被公开。