这个 Python 文件读取测试有什么问题?

Tom*_*ito 1 python file-io file

这个 Python 文件读取测试有什么问题?

import os
import sys

fileList = os.listdir(sys.argv[1])
count = 0
for file in fileList:
    try:
        count += 1
        print os.path.isfile(file)
        if os.path.isfile(file)
            print "File >> " + file
        else
            print "Dir >> " + file
    except err:
        print "ERROR: " + err
        print ">> in file: " + file
Run Code Online (Sandbox Code Playgroud)

给出:

文件“test.py”,第 10 行 if os.path.isfile(file) ^ SyntaxError: 无效语法

为什么?

Dan*_*anJ 5

if 和 else 行缺少冒号

if (something):   #note the : at the end
  ...
else:
  ...
Run Code Online (Sandbox Code Playgroud)