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

Fredrik Lundh fredrik at pythonware.com
Mon Nov 20 14:21:55 EST 2006


Tom Mountney wrote:

> if __name__ == "__main__":
>  (g = dirGrep("c:\\winnt"))
>  files = g.findFiles(".py")
>  print g.findLines("java", files)
> 
> When I try to run the program - python grep.py - I get the following error:
> 
> C:\> python grep.py
>   File "grep.py", line 28
>     if __name__ == '__main__':
>                                              ^
> SyntaxError: invalid syntax

on my machine, I get

C:\> python grep.py
   File "grep.py", line 29
     (g = dirGrep("c:\\winnt"))
        ^
SyntaxError: invalid syntax

which at least points to the right line.  the error here is that you 
cannot put parentheses around an assignment in Python; grouping parens 
can only be used in expressions, and assignment isn't an expression in 
Python.

</F>




More information about the Python-list mailing list