Help!!! New to Python and getting an error I can't figure out

John Machin sjmachin at
Mon Nov 20 20:23:45 CET 2006

Tom Mountney wrote:
> Any help is greatly appreciated!!!
> I'm learning python and from a book I tried this program: (all the
> indentation is there just doen't appear in this EMail)

Some books have websites from which you can download the source of
examples so you don't have to type them in carefully yourself; is this
one not so?

> ----------------------------------------------------------


>  def findfiles(self, pattern):
>   "Accepts pattern, returns filenames that contain pattern"
>   return[x for x in self.files if x.find(pattern) != -1

You are missing a bracket ("]") off the end of this line. Python allows
automatic statement continuation while there are excess left
parentheses brackets & braces, so you don't get told about the error
until the next line.

BTW, most modern text editors and IDEs have some sort of assistance
with ()[]{}

> #test
> if __name__ == "__main__":
>  (g = dirGrep("c:\\winnt"))
>  files = g.findFiles(".py")
>  print g.findLines("java", files)
> When I try to run the program - python - I get the following error:
> C:\> python
>   File "", line 28
>     if __name__ == '__main__':
>                                              ^
> SyntaxError: invalid syntax
> What am I doing wrong?
> Thanks for any help


More information about the Python-list mailing list