from string import Template default = "\underline{\hspace{1cm}}" checked = "\underline{\hspace{0.35cm}X\hspace{0.35cm}}" d = {} d['account_number'] = "602382.3" d['trader_name'] = 'Guillaume Horel' for tradetype in ['rf', 'df', 'sell', 'buy']: d['tradetype_'+tradetype] = default for currency in ['USD', 'EURO', 'CAD', 'YEN']: d['currency_'+currency] = default for settle in ['DTC', 'FED', 'EUROCLEAR', 'LOCAL']: d['settle_'+settle] = default d['tradetype_buy'] = checked d['currency_USD'] = checked d['settle_DTC'] = checked d['id_security'] = '45670AAA9' d['class_security'] = 'C' d['settle_date'] = '2013-05-18' d['date'] = '2013-05-18' d['trade_date'] = '2013-05-18' d['curr_face'] = "1000000" d['orig_face'] = "1000000" d['principal'] = "1000000" d['interest'] = "10000" d['commission'] = "0" d['net_amount'] = "0" with open("templates/trading_form.tex", "r") as fh: texfile = Template(fh.read()) texfile = texfile.substitute(d) with open("templates/trading_form_filled.tex", "w") as fh: fh.write(texfile)