最新消息:本站所有跳转向bbs.ykit.cn的附件将全面停止,附件已转移到https://www.qingsj.com

python 中os模块os.path.exists()含义

Python 有客 601浏览

os即operating system(操作系统),Python 的 os 模块封装了常见的文件和目录操作。

os.path模块主要用于文件的属性获取,exists是“存在”的意思,所以顾名思义,os.path.exists()就是判断括号里的文件是否存在的意思,括号内的可以是文件路径。

举个栗子:

user.py为存在于当前目录的一个文件

输入代码: 

import os
path = os.path.exists('user.py')
print(path)

输出结果: 

True
 
Process finished with exit code 0

如果不存在,返回的则是FALSE。

转载请注明:有客帮 » python 中os模块os.path.exists()含义