Jun-16-2025, 02:06 PM
I'd like to be able to convert any Python expressions to a string. Something like this:
However, before giving up, I wanted to ask if there might be some trick with
def show(a):
print(stringify(a))
>>> show(5 + 4)
"5 + 4"In C, the above is pretty easy but it uses pre-processor macros. But to my knowledge, in Python the expressions 5 + 4 is evaluated before the show() function is even called.However, before giving up, I wanted to ask if there might be some trick with
inspect or ast that might work.
