[Python-3000] print() flushing problem.

Wojciech Walczak wojtek.gminick.walczak at gmail.com
Wed Nov 7 15:05:01 CET 2007


2007/11/7, Christian Heimes <lists at cheimes.de>:
> Wojciech Walczak wrote:
> > Hello,
> >
> > py3k's print() is not flushing when end is set to '' and all it has to
> > print is one-character-long string:
>
> Good catch! I tried to reproduce the debug in a unit test but it's not
> easy. Your patch was a good head start but I didn't like the fact that
> it was calling flush() when end is set. It should only call flush when
> end is an empty string.
>
> Comments?
>
>         if (end == NULL || end == Py_None) {
>                 err = PyFile_WriteString("\n", file);
>         }
>         /* case: end='', the existence of stdout.flush is not mandatory. */
>         else if (*PyUnicode_AsString(end) == '\0') {
>                 tmp = PyObject_CallMethod(file, "flush", "");
>                 if (tmp == NULL)
>                         PyErr_Clear();
>                 else
>                         Py_DECREF(tmp);
>         }
>         else {
>                 err = PyFile_WriteObject(end, file, Py_PRINT_RAW);
>         }

I was trying that way too, but it won't work in that particular case:

>>> print('x',end='')
x>>> print('',end='x')
>>> print()
x
>>>


Wojtek Walczak


More information about the Python-3000 mailing list