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:
...
精彩评论