[Python-Dev] eval and triple quoted strings (original) (raw)
Guido van Rossum guido at python.org
Sat Jun 15 22:23:46 CEST 2013
- Previous message: [Python-Dev] eval and triple quoted strings
- Next message: [Python-Dev] eval and triple quoted strings
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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).
--Guido van Rossum (sent from Android phone) On Jun 15, 2013 1:03 PM, "Ron Adam" <ron3200 at gmail.com> wrote:
On 06/14/2013 04:03 PM, PJ Eby wrote: >Should this be the same? > > >python3 -c 'print(bytes("""\r\n""", "utf8"))' >b'\r\n' > >
>>>>eval('print(bytes("""\r\n"**"", "utf8"))')
>b'\n' No, but: eval(r'print(bytes("""\r\n""", "utf8"))') should be. (And is.) What I believe you and Walter are missing is that the \r\n in the eval strings are converted early if you don't make the enclosing string raw. So what you're eval-ing is not what you think you are eval-ing, hence the confusion. Yes thanks, seems like an easy mistake to make. To be clear... The string to eval is parsed when the eval line is tokenized in the scope containing the eval() function. The eval function then parses the resulting string object it receives as it's input. There is no mention of using raw strings in the docs on evel and exec. I think there should be, because the intention (in most cases) is for eval to parse the string, and not for it to be parsed or changed before it's evaluated by eval or exec. An example using a string with escape characters might make it clearer. Cheers, Ron _______** Python-Dev mailing list Python-Dev at python.org http://mail.python.org/**mailman/listinfo/python-dev<http://mail.python.org/mailman/listinfo/python-dev> Unsubscribe: http://mail.python.org/mailman/options/python-dev/ guido%40python.org<http://mail.python.org/mailman/options/python-dev/guido%40python.org> -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20130615/cd5895e2/attachment.html>
- Previous message: [Python-Dev] eval and triple quoted strings
- Next message: [Python-Dev] eval and triple quoted strings
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]