[Tutor] findall()

Dragonfirebane at aol.com Dragonfirebane at aol.com
Sat Jul 3 02:06:05 EDT 2004


Hello list.

I'm trying to get the following code to work:

def getlog(activity,type,endtype):
    log = open("Multivert_Log.txt","r")
    for line in log.readlines():
        ac = re.compile(activity)
        fac = re.findall(ac, line)
        if fac:
            print line
            break
        else:
            print "Uh-oh."
    log.close()
    logagain = open("Multivert_Log.txt","r")
    ty = re.compile(type)
    fty = re.findall(ty,line)
    for line in logagain.readlines():
        if not fty:
            fty = re.findall(ty,line)
        elif fty:
            print line
            break
    logagain.close()
    ex = re.compile("\d")
    fex = re.findall(ex,line)
    logain = open("Multivert_Log.txt","r")
    for line in logain.readlines():
        if not fex:
            fex = re.findall(ex,line)
        elif fex:
            print line
            break

If, for example, [readlines():] returns:

"CALCULATION 





EXPONENTS 



1 ** 1 = 1 
",
the code poduces:

"CALCULATION 



"

Any suggestions as to how to go about this, as well as to why the program 
behaves this way, are welcome.

Thanks in advance,
Orri

Email: dragonfirebane at aol.com
AIM: singingxduck
Programming Python for the fun of it.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20040703/98f19357/attachment.html


More information about the Tutor mailing list