from string import Template # Read the content of files with open("access-list-values.txt", "r") as f: access_list_values_template = Template(f.read()) with open("access-list-parsers.txt", "r") as f: parsers = f.read() # Substitute values into the template d = { "services_groups": "1|2|3|4|5|5|5" "services_objects": "1|2|3|4", } access_list_values = access_list_values_template.substitute(d) # Write to the output file with open("access-list.txt", "w") as f: f.write(access_list_values) f.write(parsers) print(access_list_values) print(parsers)