简体   繁体   English

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

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

What's wrong with this Python file-read test? 此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

gives: 得到:

File "test.py", line 10 if os.path.isfile(file) ^ SyntaxError: invalid syntax 如果是os.path.isfile(file),则文件“ test.py”,第10行^ SyntaxError:语法无效

why? 为什么?

missing colon on if and else lines if和else行上缺少冒号

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM