4 ms·
Just had a quick look at a few of the python examples: - it might be neat, but advocating for `eval(input())` [0] might not be the safest solution for this pro
by infinityio 5y ago
Just had a quick look at a few of the python examples:
- it might be neat, but advocating for `eval(input())` [0] might not be the safest solution for this problem, especially without explaining the dangers of `eval` (assuming this site is partially aimed at beginners?)
- for an article titled 'how to terminate a script', the suggested method (`quit()`) [1] is specifically described in the official python docs [2] as code that "should not be used in programs".
[0]: https://onelinerhub.com/python/calculator https://onelinerhub.com/python/calculator
[1]: https://onelinerhub.com/python/how-to-terminate-script https://onelinerhub.com/python/how-to-terminate-script
[2]: https://docs.python.org/3/library/constants.html#constants-added-by-the-site-module https://docs.python.org/3/library/constants.html#constants-a...
- kortex 5y agoI agree eval is pretty gross and folks should not be encouraging its use since it can lead to bad habits. Quit/exit are pretty innocuous though. I actually just thought exit was an alias for sys.exit. I've never had a problem using plain exit() in programs.