[Python] A problem for Python hackers. How good your knowledge is?

Can you create a printf-like function?

my_printf("%d %s hello\n", [1234, "test"])
But f-style strings must also work (without f-strings):
x=123
y=456
my_printf("{x+y}")

...

l=[1,2,3]
my_printf("{l}")

This should be also supported:

import math

...

my_printf("{2+2} {5*6} {math.sin(1.234)}")

...

x=1.234
s="{math.sin(x)}"
my_printf(s)

This is doable even in Python 2.x, without f-strings support, in 10-30 lines of code, maybe.

You can ask me by email, if you solved it correctly.

UPD: the solution.


Please drop me email about bug(s) and/or suggestion(s): my emails. List of my other blog posts.