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         #.    

  

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-06
  • 2021-10-15
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-29
  • 2022-12-23
  • 2021-10-29
  • 2021-06-11
  • 2021-10-22
  • 2022-12-23
相关资源
相似解决方案