Improving my text processing script

Miki Tebeka miki.tebeka at zoran.com
Thu Sep 1 04:33:19 EDT 2005


Hello pruebauno,

> import re
> f=file('tlst')
> tlst=f.read().split('\n')
> f.close()
tlst = open("tlst").readlines()

> f=file('plst')
> sep=re.compile('Identifier "(.*?)"')
> plst=[]
> for elem in f.read().split('Identifier'):
> 	content='Identifier'+elem
> 	match=sep.search(content)
> 	if match:
> 		plst.append((match.group(1),content))
> f.close()
Look at re.findall, I think it'll be easier.

> flst=[]
> for table in tlst:
> 	for prog,content in plst:
> 		if content.find(table)>0:
        if table in content:
> 			flst.append('"%s","%s"'%(prog,table))

> flst.sort()
> for elem in flst:
> 	print elem
print "\n".join(sorted(flst))

HTH.
--
------------------------------------------------------------------------
Miki Tebeka <miki.tebeka at zoran.com>
http://tebeka.bizhat.com
The only difference between children and adults is the price of the toys
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 193 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20050901/edbdace5/attachment.sig>


More information about the Python-list mailing list