How can I automagically resolve format specifiers in Python? For example instead of:
MagicPrint(str.format('This is {}', my.name))
I want to write MagicPrint() function as follows:
MagicPrint('This is {my.name}')
Suggestions? Maybe I can use decorators for MagicPrint()
function?
Please note that my.name
is not present in **locals()
because MagicPrint()
can be called from another module.
Used this solution to access caller's variables. Then I have automagical access to print the string.