def expand_tsv_fields(newenv, tmpl_file, tsv_file):
with open(tmpl_file, '<STR_LIT:r>') as f:<EOL><INDENT>input_lines = f.readlines()<EOL><DEDENT>with open(tsv_file, '<STR_LIT:w>') as f:<EOL><INDENT>f.write(input_lines[<NUM_LIT:0>])<EOL>for line in input_lines[<NUM_LIT:1>:]:<EOL><INDENT>curr = []<EOL>for field in line.split('<STR_LIT:\t>'):<EOL><INDENT>cell = subprocess.check_output(<EOL>'<STR_LIT>' % field, env=newenv, shell=True)<EOL>curr.append(cell)<EOL><DEDENT>f.write('<STR_LIT:\t>'.join(curr) + '<STR_LIT:\n>')<EOL><DEDENT><DEDENT>
Write a TSV file, expanding environment variables in the template.