[issue11098] syntax error at end of line in interactive python -u

STINNER Victor report at bugs.python.org
Wed Feb 2 17:05:47 CET 2011


STINNER Victor <victor.stinner at haypocalc.com> added the comment:

Since r7409 (14 years ago), Python does set the binary binary mode on stdin and stdout (not stderr) if the -u flag is used:
----
    if (unbuffered) {
#if defined(MS_WINDOWS) || defined(__CYGWIN__)
        _setmode(fileno(stdin), O_BINARY);
        _setmode(fileno(stdout), O_BINARY);
#endif
#ifdef HAVE_SETVBUF
        setvbuf(stdin,  (char *)NULL, _IONBF, BUFSIZ);
        setvbuf(stdout, (char *)NULL, _IONBF, BUFSIZ);
        setvbuf(stderr, (char *)NULL, _IONBF, BUFSIZ);
#else /* !HAVE_SETVBUF */
        setbuf(stdin,  (char *)NULL);
        setbuf(stdout, (char *)NULL);
        setbuf(stderr, (char *)NULL);
#endif /* !HAVE_SETVBUF */
    }
----

If you would like to check that the problem is related to the binary mode, you can set the binary mode manually without the -u flag. Add the following code at the end of your site.py file:
----
import msvcrt
msvcrt.setmode (0, os.O_BINARY) # stdin  = 0
msvcrt.setmode (1, os.O_BINARY) # stdout = 1
msvcrt.setmode (2, os.O_BINARY) # stderr = 2
----

Python 3.2 does always set the binary mode for all files (opened files but also stdin, stdout and stderr), which requires a fix in the parser because the parser didn't support Windows newlines (\r\n). See issue 10841 and the commit r87824 for more information.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue11098>
_______________________________________


More information about the Python-bugs-list mailing list