#!/usr/bin/env python3 from string import Template d={'domain': 'domain.com', 'IP': '1.2.3.4', 'PORT': 8000} with open('../templates/testfile') as f: src = Template(f.read()) result = src.substitute(d) print(result)