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
参考:
https://www.jb51.net/article/66452.htm