Improving my text processing script

pruebauno at latinmail.com pruebauno at latinmail.com
Wed Aug 31 11:09:42 EDT 2005


I am sure there is a better way of writing this, but how?

import re
f=file('tlst')
tlst=f.read().split('\n')
f.close()
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()
flst=[]
for table in tlst:
	for prog,content in plst:
		if content.find(table)>0:
			flst.append('"%s","%s"'%(prog,table))
flst.sort()
for elem in flst:
	print elem



What would be the best way of writing this program. BTW find>0 to check
in case table=='' (empty line) so I do not include everything.

tlst is of the form:

tablename1
tablename2

...

plst is of the form:

Identifier "Program1"
Name "Random Stuff"
Value "tablename2"
...other random properties
Name "More Random Stuff"
Identifier "Program 2"
Name "Yet more stuff"
Value "tablename2"
...


I want to know in what programs are the tables in tlst (and only those)
used.




More information about the Python-list mailing list