-2

I've got the "usual" expected an indented block. All the indentations are right. I've open my script in various editors and there is no issue abt missalignments, or hiden whitespaces caused by tabs.

Would really appreciate if anyone could shed some light on this issue.

This is the part of the script causing problems:

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

Python expects an indented block at the line if len(fsplit)>1:

Much appreciated

Jose

Ashwini Chaudhary
  • 244,495
  • 58
  • 464
  • 504
jaoc
  • 31
  • 2
  • 5
  • copy and paste it into a notepad, then check your indentations again – Layla Nov 22 '12 at 13:34
  • The doc string should be indented - also, you may want to consider looking at the `glob` module, -`glob.glob('TOCOM*.csv')` for example – Jon Clements Nov 22 '12 at 13:34

2 Answers2

7

The problem is with your docstring at the start of the function. It should be indented as well.

Tim Pietzcker
  • 328,213
  • 58
  • 503
  • 561
Emil Vikström
  • 90,431
  • 16
  • 141
  • 175
0

Indent the first line of your doc string.

Just change:

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
'''

to:

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
'''

And it should work fine.

  • 2
    This is an exact duplicate of the existing answer. I don't see adding in the (ridiculously verbose) example helps. – Gareth Latty Nov 22 '12 at 13:37
  • I started writing before the earlier answer was posted, didn't notice, my bad here. –  Nov 22 '12 at 13:38