[Tutor] invalid syntax? huh!?!
Sean 'Shaleh' Perry
shalehperry@attbi.com
Fri, 18 Oct 2002 10:51:35 -0700
On Friday 18 October 2002 10:33, Ray Leggett wrote:
> Ok, I'm writing a script in Python 2.2 on windows that basically scans
> another python module and lists all the lines beginning with "class" an=
d
> "def" in them. Basically, it will print out a reference to the module.
>
> Well, i wrote the thing in maybe 20 minutes tops. Ran it with another
> python module as an argument, and got the following:
>
> File "C:\scripts\modscan.py", line 16
> for line in fp.readlines()
> ^
> SyntaxError: invalid syntax
>
> Now, this is really puzzling to me. As far as I can tell, the for loop=
I
> used is correct in any number of languages, including python. Here is =
the
> script: (formatting a little mangled by outlook)
will assume the formatting is correct then
>
> def ScanModule(ModuleToScan):
> fp =3D open(ModuleToScan)
> for line in fp.readlines()
there is no ':' on the end of this line. A for loop's beginning statemen=
t=20
must end with a colon just like the if lines do.
> if ScanClass.search(line):
> print line
> else
ditto for 'else' statements.