开发者

What's wrong with this Python file-read test?

What's wrong with this Python file-read test?

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

gives:

File "test.py", line 10 if os.path.isfile(file) 开发者_开发知识库 ^ SyntaxError: invalid syntax

why?


missing colon on if and else lines

if (something):   #note the : at the end
  ...
else:
  ...
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜