1、判断文件和文件夹是否存在及创建
import os
#os.path.exists(dir_path/file_path) 判断内容是否存在
>>>os.path.exists(‘/home/mologa‘)
True
#os.path.isfile(file_path) 判断文件是否存在且是文件类型
>>>os.path.isfile(‘/home/mologa/a.log‘)
False
#os.path.isdir(dir_path) 判断文件夹是否存在
>>>os.path.isdir("/home/mologa/miao")
True
2、文件常用操作符
import os os.pathsep #; os.linesep #n os.pardir #.. os.sep #or/ 依系统 os.curdir #.
原文:http://www.cnblogs.com/mologa-jie/p/7808391.html
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!