שלום.
הבנתי שהפונקצייה eval() מאפשרת לי להכניס משוואות לקלט, ולהורות לפייתון לחשב אותן ולהחזיר לי ערך float (הבנתי נכון?).
עם זאת, ראיתי באינטרנט שיש לה עוד שימושים, ולא הבנתי ממש מה המשמעות מאחוריהם. בפורום בקישור ניסו להסביר, אבל לא ממש הבנתי…
יש מישהו שמבין שיכול להסביר למה התכוונו שם?:
(מסתבר שאי אפשר לפרסם לינקים בפורום הזה…)
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().
haha, that was a trivial example, but you could let the user type in an arbitrary command and have python execute it. So you could have the user type in a command string and then have python run it as code. So for example: eval("import('os').remove('file
')").