(Dec-24-2019, 12:46 PM)ibreeden Wrote: That is an interesting puzzle. After a lot of tries I succeeded in producing a working example.
>>> string_from_file = 'f"Printing {var1}"' >>> string_from_file 'f"Printing {var1}"' >>> var1 = "content of variable" >>> exec('print(eval(string_from_file))') Printing content of variable >>>Although this works I would prefer usingstring.format()
. But I am sure you thought about that already.
i don't necessarily want to print it. maybe i want to pass the result, and some there values, to a function or method. maybe the result is meant to be a file name.
(Dec-24-2019, 03:31 PM)DeaD_EyE Wrote: Maybe you want to use some existing tools: https://palletsprojects.com/p/jinja/
BTW: Merry Christmas
i don't see how Jinja, or any template engine, could achieve this.
(Dec-24-2019, 08:31 PM)snippsat Wrote: 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~~~
my goal had nothing to do with web templating.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.