x='''
print '\tone \'piece\' of \"metal\" with \\sharp\\ edge '
print '\nthanks'
'''
exec(x)
I have a string variable (x) and i want to use exec() to print it out correctly. If i have access to the variable i can directly use r' and problem solved, such as :
x=r'''
print '\tone \'piece\' of \"metal\" with \\sharp\\ edge '
print '\nthanks'
'''
exec(x)
But in this case , i don't have access to the variable. so The string variable come from other end or other user. so how can i apply this r' to the existing variable so i can use exec() .
The correct output should be :
one 'piece' of "metal" with \sharp\ edge
thanks
The real case is :
Inside my software, i can create objects and each this object can have properties such as text input and button. I will refer this text input and button properties as object.text_input and object.button. Let say i have 2 objects named as AA and BB and i type an expression/script in AA.text_input (the text input of object1). Now from BB (object2) i want to use the expression entered in AA.text_input and execute it using exec(). So in BB.button i will write a code such as : exec(AA.text_input). So the data i grab from AA will be a string. The problem is the code type in text input of AA may contain any character including escape chars and others. So when i use exec() in BB i will have error because of those chars. So the question : how to bring that string from BB.text_input correctly to AA ?