[Tutor] invalid syntax? huh!?!
Ray Leggett
rlegge@tc3net.com
Fri, 18 Oct 2002 13:33:21 -0400
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" and
"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)
--------------------------------------------------------
#!/usr/bin/python
"scans a python module and lists all classes and functions"
import sys
import re
ModuleToScan = sys.argv[1]
def SetRegExp():
ScanClass = re.compile("class")
ScanDef = re.compile("def")
def ScanModule(ModuleToScan):
fp = open(ModuleToScan)
for line in fp.readlines()
if ScanClass.search(line):
print line
else
if ScanDef.search(line):
print line
fp.close()
return
SetRegExp()
ScanModule(ModuleToScan)
--------------------------------------------------------------------------
Any ideas? This one has me really puzzled.