code to parse a file

Pedro Silva psilva at ruido-visual.pt
Thu Feb 10 09:54:44 EST 2000


Hi

I had write some code in a Python Method, a Zope Product, that will open a file and will read line-by-line and check if some string is in that line, if yes, it will return the line to a variable. 
The code I write is:

        f=open('/var/spool/news/articles/esoterica/geral/1','r')
        for lines in f.readline():
            if string.find('From:'):
                from=lines
            if string.find('Subject:'):
                sub=lines
            if string.find('Date:'):
                date=lines
            if string.find('Xref:'):
                f.seek(0,2)
                for text in f.read():
                        cont=text
        return from,sub,date,cont

Is this code correct to do what I pretend?
If not, can anyone help me to solve this?

Please send your answers to: psilva at ruido-visual.pt

Thanks,

Pedro
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20000210/9b48a0f3/attachment.html>


More information about the Python-list mailing list