os.path.isFile(file) 在 Python 2.7 中抛出错误

os.path.isFile(file) throwing error in Python 2.7

由于我的代码很简单,所以我将其完整地包括在内:

#!/usr/bin/python
import sys
import os.path
def main(argv):
    if len(sys.argv) < 3:
        print "insuficient arguments. Use like: lichcrypt <d/e> </path/to/file>"
    else:
        operation = argv[1]
        filepath = argv[2]
        print operation
        print os.path.isFile(filepath)
main(sys.argv)

错误,当来自 cmd 行的 运行 脚本样式是:

liam@liam-GA-970A-UD3:~$ lichcrypt.py something not/a/file/path
something
Traceback (most recent call last):
  File "/home/liam/bin/lichcrypt.py", line 12, in <module>
    main(sys.argv)
  File "/home/liam/bin/lichcrypt.py", line 11, in main
    print os.path.isFile(filepath)
AttributeError: 'module' object has no attribute 'isFile'

现在,这段代码显然非常无用。最终它会加密文件,但在我拿到文件之前它什么也做不了。

关于为什么 os.filepath.isFile() 似乎不再存在的任何想法?

python中的函数名区分大小写,函数是isfile不是isFile

参考 link : os.path.isfile

#!/usr/bin/python
import sys
import os.path
def main(argv):
    if len(sys.argv) < 3:
        print "insuficient arguments. Use like: lichcrypt <d/e> </path/to/file>"
    else:
        operation = argv[1]
        filepath = argv[2]
        print operation
        print os.path.isfile(filepath)
main(sys.argv)