View Single Post
Old 2014-10-31, 15:13   #3
Basketry That Evening!
Dubslow's Avatar
"Bunslow the Bold"
Jun 2011
40<A<43 -89<O<-88

3×29×83 Posts

import re
in_file = 'blah.abcd'
out = []
with open(in_file) as f:
    for line in f.readlines():
        if re.match(r'^(\d+) (\d+)$', line):
            k, n = line.split()
            out.append('PRP={},2,{},-1'.format(k, n))
out_file = 'worktodo.txt'
with open(out_file, 'w') as f:
    f.write('\n'.join(out) + '\n')
The loop could be written as an ultra-extended list comprehension:

out = ['PRP={},2,{},-1'.format(*line.split()) for line in f.readlines() if re.match(r'^(\d+) (\d+)$', line)]

Last fiddled with by Dubslow on 2014-10-31 at 15:15
Dubslow is offline   Reply With Quote