Re[2]: [Tutor] invalid syntax? huh!?!

Sean 'Shaleh' Perry shalehperry@attbi.com
Fri, 18 Oct 2002 11:17:40 -0700


On Friday 18 October 2002 10:58, Ray Leggett wrote:
> Yeah, i saw that after i posted.  But I fixed the two colons, and I sti=
ll
> get the same error message,.
>

#!/usr/bin/python

"scans a python module and lists all classes and functions"

import sys
import re

ModuleToScan =3D sys.argv[1]

def ScanModule(ModuleToScan):
    ScanClass =3D re.compile("class")
    ScanDef =3D re.compile("def")

    fp =3D open(ModuleToScan)
    for line in fp.readlines():
        if ScanClass.search(line):
            print line
        elif ScanDef.search(line):
            print line
    fp.close()
    return

ScanModule(ModuleToScan)

works here.

I moved ScanClass and ScanDef into ScanModule because otherwise they woul=
d not=20
be defined.  Putting them in a separate function would have made sense if=
=20
they were also declared global.

Pay attention to whitespace, things must line up.