I am sure there is a better way of writing this, but how?
import re
f=file('tlst')
tlst=f.read().s plit('\n')
f.close()
f=file('plst')
sep=re.compile( 'Identifier "(.*?)"')
plst=[]
for elem in f.read().split( 'Identifier'):
content='Identi fier'+elem
match=sep.searc h(content)
if match:
plst.append((ma tch.group(1),co ntent))
f.close()
flst=[]
for table in tlst:
for prog,content in plst:
if content.find(ta ble)>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.
import re
f=file('tlst')
tlst=f.read().s plit('\n')
f.close()
f=file('plst')
sep=re.compile( 'Identifier "(.*?)"')
plst=[]
for elem in f.read().split( 'Identifier'):
content='Identi fier'+elem
match=sep.searc h(content)
if match:
plst.append((ma tch.group(1),co ntent))
f.close()
flst=[]
for table in tlst:
for prog,content in plst:
if content.find(ta ble)>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.
Comment