开发者

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

开发者 https://www.devze.com 2023-01-31 22:33 出处:网络
What\'s wrong with this Python file-read test? import os import sys fileList = os.listdir(sys.argv[1]) count = 0

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

精彩评论

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