Does Python 3.1 accept \r\n in compile()?

J

jmfauth

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.

In Python 3.1, it does not seem to be the case.

(Python 3.2.a/b not checked).

Bug, regression, deliberate choice?

2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit
(Intel)]
'3.1.2 (r312:79149, Mar 21 2010, 00:41:52) [MSC v.1500 32 bit
(Intel)]'
Traceback (most recent call last):
File "<qsi last command>", line 1, in <module>
File "<in>", line 1
if True:

^
SyntaxError: invalid syntax
 
T

Terry Reedy

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
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.
 
T

Terry Reedy

"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."

Retest shows that above is correct.

<code object <module> at 0x00F5EC50, file "blah", line 1>

For most development purposes (not just yours), 3.2b2 is already better
than 3.1.

Terry Jan Reedy
 
J

jmfauth

Retest shows that above is correct.

 >>> compile("print(999)\r\n", "blah", "exec")

<code object <module> at 0x00F5EC50, file "blah", line 1>

Ok, I see. Thanks.

The '\r\n' acceptance has been introduced in Python 2.7
and I was a little bit suprised with Python 3.1.

For the story, I'm not using directly the compile()
command, but something like:

<my_interactive_interpreter_instance>.runsource(source)

where source is coming from a GUI toolkit text widget.
 
T

Terry Reedy

Ok, I see. Thanks.

The '\r\n' acceptance has been introduced in Python 2.7
and I was a little bit suprised with Python 3.1.

2.6 was followed by 3.0 and then 3.1.
2.7 will be followed by 3.2 in a couple more month.
That feature was added to 2.7 and 3.2 in Nov 2009 long after 3.1.
 
J

jmfauth

2.6 was followed by 3.0 and then 3.1.
2.7 will be followed by 3.2 in a couple more month.
That feature was added to 2.7 and 3.2 in Nov 2009 long after 3.1.

Thanks for these precisions and don't worry too much, it's
not a real isssue.

(I'v seen the "noise" on the pydev list).

Thanks again.
 
J

jmfauth

Just an info, addendum.
'3.2rc1 (r32rc1:88035, Jan 15 2011, 21:05:51) [MSC v.1500 32 bit
(Intel)]'
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top