4 ms·
In twenty years of professional Python development, I've never used eval once. I'm not saying nobody ever needs it, but it's a niche feature that the vast major
by StavrosK 6y ago
In twenty years of professional Python development, I've never used eval once. I'm not saying nobody ever needs it, but it's a niche feature that the vast majority of programs can do without, and is probably not worth the tradeoff.
- jononor 6y agoYou probably have used a Python REPL though? Either on commandline or in iPython shell or similar. This relies on eval type functionality somewhere in the chain.
- _ZeD_ 6y agohave you ever used namedtuple? then you have: https://bugs.python.org/issue3974 https://bugs.python.org/issue3974
- duckerude 6y agonamedtuple could be implemented without exec/eval, and nowadays, it almost is. This is the only part left that uses it, to create the constructor: https://github.com/python/cpython/blob/master/Lib/collections/__init__.py#L430 https://github.com/python/cpython/blob/master/Lib/collection... Even there it's not strictly necessary. You could accomplish the same thing with a variadic function that does its own argument parsing, it'd just be slower and not play as well with reflection. So you could port it to a Python implementation without eval().
- danijar 6y agoIt's necessary if you want to offer an interactive Python shell in the browser, e.g. for websites that teach programming or otherwise use programming as a means of user interaction.
- airstrike 6y agoWhich is like 0.0001% of the web