Windows Python 2.4: Unbuffered flag causes SyntaxError on interactive sessions?

L

Lonnie Princehouse

From the cmd shell on both Windows 2k and XP, I'm getting this weird
syntax error in conjunction with the unbuffered flag. It works fine
without -u. Has anyone else encountered it? This didn't happen with
Python 2.2...

C:\>python -u
Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)]
on win32
Type "help", "copyright", "credits" or "license" for more information. File "<stdin>", line 1
print 'hello'
^
SyntaxError: invalid syntax


(sorry if this is a known/fixed bug... I couldn't find anything about
it)
 
M

Michael Hoffman

Lonnie said:
C:\>python -u
Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)]
on win32
Type "help", "copyright", "credits" or "license" for more information.

File "<stdin>", line 1
print 'hello'
^
SyntaxError: invalid syntax

Worksforme:

C:\Python24>python.exe -u
Python 2.4.1 (#65, May 24 2005, 13:43:04) [MSC v.1310 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.hello

Strange that your python build is from 30 March and mine is from 24 May.
 
I

Irmen de Jong

Michael said:
Lonnie said:
C:\>python -u
Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)]
on win32
Type "help", "copyright", "credits" or "license" for more information.
print 'hello'


File "<stdin>", line 1
print 'hello'
^
SyntaxError: invalid syntax


Worksforme:

C:\Python24>python.exe -u
Python 2.4.1 (#65, May 24 2005, 13:43:04) [MSC v.1310 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.hello

Strange that your python build is from 30 March and mine is from 24 May.


Problem also occurs on my machine using Win XP Home,
Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on win32


even just typing "print" at the interactive prompt causes a syntax error...

--Irmen
 
L

Lonnie Princehouse

Weird. Did you build Python yourself? The 2.4.1 release on python.org
is from March 30.
I just tried ActiveState's 2.4.1... the same thing happens.
 
T

Terry Reedy

Lonnie Princehouse said:
Weird. Did you build Python yourself? The 2.4.1 release on python.org
is from March 30.
I just tried ActiveState's 2.4.1... the same thing happens.

Please report this on the SourceForge bug list, including the details of
the two releases and de Jong's confirmation (and even Hoffman's
non-confirmation). The 2.4.2 release process starts soon and it would be
nice to have this fixed.

Terry J. Reedy
 
R

Reinhold Birkenfeld

Irmen said:
Michael said:
Lonnie said:
C:\>python -u
Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)]
on win32
Type "help", "copyright", "credits" or "license" for more information.

print 'hello'


File "<stdin>", line 1
print 'hello'
^
SyntaxError: invalid syntax


Worksforme:

C:\Python24>python.exe -u
Python 2.4.1 (#65, May 24 2005, 13:43:04) [MSC v.1310 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
print 'hello'
hello

Strange that your python build is from 30 March and mine is from 24 May.


Problem also occurs on my machine using Win XP Home,
Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on win32


even just typing "print" at the interactive prompt causes a syntax error...

It __may__ be that this is caused by an error in the codecs machinery which is already
fixed in 2.4 CVS. Could you try this out?

Reinhold
 
L

Lonnie Princehouse

After doing some more reading, I now think this isn't a bug.

Evidently the unbuffered flag not only makes stdin unbuffered, but it
also forces it into binary mode. I didn't realize that when I posted
earlier.

So the SyntaxErrors arise because the interpreter isn't converting \r\n
into \n because stdin is binary. Not a bug, although it would be nice
to have an "unbuffered text mode" flag too...

D'oh.
 
M

Michael Hoffman

Lonnie said:
Evidently the unbuffered flag not only makes stdin unbuffered, but it
also forces it into binary mode. I didn't realize that when I posted
earlier.

So the SyntaxErrors arise because the interpreter isn't converting \r\n
into \n because stdin is binary. Not a bug, although it would be nice
to have an "unbuffered text mode" flag too...

so if you do this:
zzz

Does z contain 'zzz\r'?

For me, it just contains 'zzz'.
 
S

Steve Holden

Lonnie said:
After doing some more reading, I now think this isn't a bug.

Evidently the unbuffered flag not only makes stdin unbuffered, but it
also forces it into binary mode. I didn't realize that when I posted
earlier.

So the SyntaxErrors arise because the interpreter isn't converting \r\n
into \n because stdin is binary. Not a bug, although it would be nice
to have an "unbuffered text mode" flag too...

D'oh.
It seems a little bizarre to me that the compiler isn't prepared to
treat carriage returns as whitespace during its tokenizations. The only
area I would anticipate problems would be string literals containing
end-of-line sequences embedded within triple-quotes.

It would seem to make sense to program the compiler defensively to
ignore embedded "\r" characters.

regards
Steve
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top