Today I was wondering about the limitations of python formatting of strings. For example, say you want to build this kind of string : ${SOME_APPLICATION_VAR}
If SOME_APPLICATION_VAR is not known in advance, how would you build this string ?
I tried "${{}}".format(variable_name) but it yields ${}. I understand why but I can't find a way to achieve my goal. A lot of attempts were awarded with exceptions.
Could someone give me some clues about how to do that ?
You need to use 3 of each bracket. 2 get resolved into a literal set of brackets, and the last set acts as the placeholder for the formatting.
print("${{{}}}".format(variable_name))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With