shaoheshaohe 发表于 2019-4-29 15:40:38

python判断文件是否存在

import os

filename = r'/home/tim/workspace/test.txt'
if os.path.exists(filename):
    message = 'OK, the "%s" file exists.'
else:
    message = "Sorry, I cannot find the "%s" file."
print message % filename
页: [1]
查看完整版本: python判断文件是否存在