code to parse a file
Thomas Weholt
thomas at bibsyst.no
Thu Feb 10 10:37:32 EST 2000
> Pedro Silva wrote:
>
> 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
If I`m not mistaken, your posting is written in, or at least sent as,
HTML. Not smart when posting to newsgroups. I don`t actually care, but
you`ll get alot of flak from text-based-newsreading-hardcore kinda
people. And most people, probably the same group, will not bother to
send answers directly to your email adress, but send it all to the
newsgroup. I`ve tried this and that`s how I know. ;->
Did I answer your python-question? Well ....
Thomas
More information about the Python-list
mailing list