繁体   English   中英

Python 错误:“应为缩进块”

[英]Python error: "expected an indented block"

我得到了“通常”预期的缩进块。 所有的缩进都是正确的。 我已经在各种编辑器中打开了我的脚本,并且没有出现错误对齐或由制表符引起的隐藏空格的问题。

如果有人能对这个问题有所了解,我将不胜感激。

这是导致问题的脚本部分:

def findCSVs():
'''
looks into a 'tocom_data' subdirectory, finds 'tocomxxx.csv' files,
retuns a sorted list of filenames that conform: begins with TOCOM, ends in .csv
'''
    csvlist = []
    datadir=os.path.join('.','tocom_data')
    flist = os.listdir(datadir)
    for fname in flist:
        fsplit = fname.split('.')
        if len(fsplit)>1:
            if fsplit[1]=="csv" and fname[0:5]=="TOCOM":
                completeFname= os.path.join(datadir,fname)
                csvlist.append(completeFname)
                csvlist.sort()
    return csvlist

if len(fsplit)>1: Python 期望在该行if len(fsplit)>1:一个缩进块if len(fsplit)>1:

非常感激

何塞

问题在于函数开头的文档字符串。 它也应该缩进。

缩进文档字符串的第一行。

只是改变:

def findCSVs():
'''
looks into a 'tocom_data' subdirectory, finds 'tocomxxx.csv' files,
retuns a sorted list of filenames that conform: begins with TOCOM, ends in .csv
'''

到:

def findCSVs():
    '''
looks into a 'tocom_data' subdirectory, finds 'tocomxxx.csv' files,
retuns a sorted list of filenames that conform: begins with TOCOM, ends in .csv
'''

它应该可以正常工作。

暂无
暂无

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

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