problem with string.lower function

Peter Hansen peter at engcorp.com
Mon Apr 28 14:27:13 EDT 2003


Don Low wrote:
> 
> def filefind(word, filename):
>         count = 0
>         try:
>                 fh = open(filename, 'r')
>         except:
>                 print filename, ":", sys.exc_info()
> 
>         allLines = fh.readlines()
>         fh.close()
> 
>         for eachLine in allLines:
>         test = string.lower(eachLine) // change is here
>         if string.find(test, word) > -1:
>                 count = count + 1
>                 print eachLine,
> 
> When I run the script, however, I get the following:
> 
>  File "2bin/./fgrepwc.py", line 37
>                  if string.find(eachLine, word) > -1:
>              ^
> SyntaxError: invalid syntax

Your indentation is almost certainly messed up.  Please make
sure you are using *spaces only*, or that you are using tabs
consistently (but really, it's better to avoid TABs!) or you
might get the above types of problem.

If you are not mixing in TABs, then the problem is simply that
the lines after the "for" statement are not indented at all,
but in Python indentation is used to denote blocks so you *must*
indent all lines in the subblock by the same amount, and more than
the for statement's indentation, or you'll have broken code.

-Peter




More information about the Python-list mailing list