Does Python 3.1 accept \r\n in compile()?
Terry Reedy
tjreedy at udel.edu
Wed Dec 29 14:31:37 EST 2010
On 12/29/2010 11:07 AM, jmfauth wrote:
> I wrote miscellaneous interactive interpreters and
> I fall on this.
>
> In Python 2.7 (understand Python> 2.6), a source code
> can be compiled with "native" '\r\n' as eol.
I am a bit surprised, but I presume this is one on many
back-compatibility holdovers still in 2.7. I believe 2.7 normally reads
input with universal newline support, so that line endings are fixed on
input, where they should be. Within Python, 'newline' is '\n'.
> In Python 3.1, it does not seem to be the case.
In 3.0, there were many simplifications where old things got dropped.
> (Python 3.2.a/b not checked).
I have not heard of any change. The compile() entry has the following:
"Changed in version 3.2: Allowed use of Windows and Mac newlines. Also
input in 'exec' mode does not have to end in a newline anymore. Added
the optimize parameter."
The second and third statement are true, but
>>> compile('print(999)\r\n', '<in>', 'exec')
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
compile('print(999)\r\n', '<in>', 'exec')
File "<in>", line 1
print(999)
^
SyntaxError: invalid syntax
I will inquire on pydev.
> Bug, regression, deliberate choice?
I presume deliberate simplification, but you can wait for another answer
or check svn logs of the appropriate source file.
Or there might be an entry in 3.0 NEWS or What's New files.
--
Terry Jan Reedy
More information about the Python-list
mailing list