a='''b="ddd"'''
eval(repr(a))
print str(a)
print b
Please try to use the code, rather than text, because my English is not very good, thank you
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use:
instead of:
Transcript:
The problem is that you’re actually executing the statement
'b="ddd"'which is not an assignment tobbut an evaluation of the string.The
eval()built-in, when given a string, evaluates it as an expression (not a statement) and returns the result. You can geteval()to run non-expression code by giving it a code object, which we create withcompile()above. In that case it runs the code and returnsNone.You can see a similar effect if you just enter:
Clearly
7=dis not valid Python, yet'7=d'is, for the reason explained above.Descriptions of the
expr(),repr()andcompile()built-ins, adequate enough to work this out, were found here. No built-ins were harmed during the making of this answer.