In the book that I am reading on Python, it keeps using the code eval(input(\'blah\'))
I read the documentation, and I understand it, but I still do no
eval()
interprets a string as code. The reason why so many people have warned you about using this is because a user can use this as an option to run code on the computer. If you have eval(input())
and os
imported, a person could type into input()
os.system('rm -R *')
which would delete all your files in your home directory. (Assuming you have a unix system). Using eval()
is a security hole. If you need to convert strings to other formats, try to use things that do that, like int()
.