1. 首页
  2. 操作系统
  3. Unix
  4. 详解python os.path.exists判断文件或文件夹是否存在

详解python os.path.exists判断文件或文件夹是否存在

上传者: 2020-12-17 07:34:13上传 PDF文件 40.3KB 热度 25次
os即operating system(操作系统),Python 的 os 模块封装了常见的文件和目录操作。 os.path模块主要用于文件的属性获取,exists是“存在”的意思,所以顾名思义,os.path.exists()就是判断括号里的文件是否存在的意思,括号内的可以是文件路径。 举个栗子: import os #判断文件夹是否存在 dir = os.path.exists('C:\\Users\\Desktop') print('dir:', dir) #判断文件是否存在 file = os.path.exists('C:\\Users\\Desktop\\雍正王朝.txt')
下载地址
用户评论