import sys scale = 1.5 def transform(): with open(sys.argv[1]) as f: for line in f.readlines(): if line.strip().startswith("' yield template else: yield line lines = list(transform()) with open(sys.argv[1], 'w') as f: f.write('\n'.join(lines))