# coding=utf-8
import os
if __name__ == '__main__':
if os.path.isfile('test.txt'):
print ("test.txt exist")
else:
print ("test.txt not exist")
if os.path.isfile('hello.py'):
print ("hello.py exist")
else:
import os
if __name__ == '__main__':
if os.path.isfile('test.txt'):
print ("test.txt exist")
else:
print ("test.txt not exist")
if os.path.isfile('hello.py'):
print ("hello.py exist")
else:
print ("hello.py not exist")
本文提供了一个简单的Python脚本示例,用于检查指定文件是否存在。通过使用os模块中的path.isfile方法,可以轻松实现这一功能。示例中包括了如何针对'test.txt'和'hello.py'两个文件进行检查。
1765

被折叠的 条评论
为什么被折叠?



