7 ms·
Short answer: no. Long answer: I have used it as part of a function that generates functions when I was writing an AST-generating portion of a parser. You need
by wzdd 16y ago
Short answer: no.
Long answer: I have used it as part of a function that generates functions when I was writing an AST-generating portion of a parser. You need to make a bunch of similar functions, so you make a list of tuples containing all the bits that differ between the functions, then write a generator function which converts these strings into real Python functions which you can then eval in global context. Surprisingly enough this actually made the code more readable and easier to maintain. :)
But that is literally the only time I have ever thought it was a good idea -- and that's in code where I completely control the data going to exec(), in code that will never be in an Internet-facing arrangement.