[issue36911] ast.parse outputs ast.Strs which do not differentiate between the ASCII codepoint 12 (literal new line) and the ASCII codepoints 134 and 156 ("\n")
Eric V. Smith
report at bugs.python.org
Tue May 14 16:11:38 EDT 2019
Eric V. Smith <eric at trueblade.com> added the comment:
The existing behavior is what I'd expect.
Using python3:
>>> import ast
>>> s = open('file.py', 'rb').read()
>>> s
b'"""\nHello \\n blah.\n"""\n'
>>> ast.dump(ast.parse(s))
"Module(body=[Expr(value=Str(s='\\nHello \\n blah.\\n'))])"
>>> eval(s)
'\nHello \n blah.\n'
As always with the AST, some information is lost. It's not designed to be able to round-trip back to the source text.
----------
nosy: +eric.smith
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue36911>
_______________________________________
More information about the Python-bugs-list
mailing list