As you see, ifinner is a string, so if I just write after if, always will be true. What can i do, to concert it to source code?
x=2
ifinner = "x==3"
if ifinner:
print("Yeah")
else:
print("It works!")
As you see, ifinner is a string, so if I just write after if, always will be true. What can i do, to concert it to source code?
x=2
ifinner = "x==3"
if ifinner:
print("Yeah")
else:
print("It works!")
Try this:
For detailed info, read the documentation of eval and exec in python 2.x/3.x. A similar question was asked previously.Here's the link
You can use
eval()
function to evaluate Python source code.Quoting the documentation: