[Python-Dev] eval and triple quoted strings

Ron Adam ron3200 at gmail.com
Sun Jun 16 04:00:13 CEST 2013



On 06/15/2013 03:23 PM, Guido van Rossum wrote:
> The semantics of raw strings are clear. I don't see that they should be
> called out especially in any context. (Except for regexps.) Usually exec()
> is not used with a literal anyway (what would be the point).


There are about a hundred instances of eval/exec(some_string_literal) in 
pythons library.  Most of them in the tests, and maybe about half of those 
testing the compiler, eval, and exec.

egrep -owr --include="*.py" "(eval|exec)\(('.*'|\".*\")\)" * | wc -l
114


I have no idea in how many places a string literal is assigned to a name 
first and then used later in eval or exec.  It's harder to grep for but 
would be less than...

egrep -owr --include="*.py" "(eval|exec)\(.*\)" * | wc -l
438

That's overstated because some of those are comments, and some may be 
functions with the name ending with eval or exec.


I do think that eval and exec is a similar case to regexps.  And possibly 
often enough, the string may contain a raw string, regular expression, or a 
file/path name.

Only a short note needed in the docs for eval, nothing more.  And not even 
that if no thinks it's an issue.

cheers,
    Ron












More information about the Python-Dev mailing list