Reputation: 28345
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?
Upvotes: 1
Views: 3057
Reputation: 3495
missing colon on if and else lines
if (something): #note the : at the end
...
else:
...
Upvotes: 5