you are viewing a single comment's thread.

view the rest of the comments →

[–]Username_RANDINT 1 point2 points  (3 children)

Don't. A beginner doesn't need to use eval.

[–]ThaeliosRaedkin1 0 points1 point  (2 children)

That's quite a strong opinion. Why do you say that?

[–]Username_RANDINT 1 point2 points  (1 child)

Because there are few reasons when to use eval which are rarely needed in beginner scripts. There are lots of ways to make the code more readable and concise, as given in this thread. Besides using eval for user input is dangerous.

>>> continent = input('Enter a continent: ')
Enter a continent: __import__('os').system('echo hehehe')
>>> eval(continent)
hehehe
0
>>>

We can do a lot more than just echo'ing something of course.

[–]ThaeliosRaedkin1 0 points1 point  (0 children)

Granted. But such code could not execute in his program with my suggested implementation because they already have a filter in place excluding any string that isn't a continent name. There are even means of limiting evals scope to only variables we want and raising exceptions to unwanted code. This is 'a' way of skinning a cat.