I agree look into jinja,sometime it easy to forget that is stand alone and very powerful,not only for web templating.
from jinja2 import Template def multi_str(word, numb): return f' '.join([f'{word.upper():~^21}'] * numb) from_file = "Hello {{ multi_str('Merry Christmas', 3) }}" template = Template(from_file) print(template.render(multi_str=multi_str)) # or #print(template.render({'multi_str': multi_str})
Output:Hello ~~~MERRY CHRISTMAS~~~ ~~~MERRY CHRISTMAS~~~ ~~~MERRY CHRISTMAS~~~