How to check if an argv refers to an existing file in python2.7?
This question already has an answer here:
import os
os.path.exists(path)
Will return True, if the path exists.
os.path.isfile(path)
Will return True, if the path is a file.
isfile可能是你正在寻找的东西。
from os.path import isfile
from sys import argv
if len(argv) > 1:
print "is file", isfile(argv[1])
链接地址: http://www.djcxy.com/p/7314.html