How to check if an argv refers to an existing file in python2.7?

This question already has an answer here:

  • How to check whether a file exists? 39 answers

  • 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

    上一篇: 如果它存在于python中,如何返回文件路径

    下一篇: 如何检查argv是否引用python2.7中的现有文件?