使用os
模块非常容易。
from os.path import exists
print exists("C:\somefile.txt")
查阅手册即可,这是一个非常简单的问题:
http://docs.python.org/library/os.path.html#os.path.exists
os.path.exists(path)
Return True if path refers to an existing path. Returns False for broken symbolic links. On some platforms, this function may return False if permission is not granted to execute os.stat() on the requested file, even if the path physically exists.