[Python-3000] print() flushing problem.

Christian Heimes lists at cheimes.de
Wed Nov 7 14:51:43 CET 2007


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);
	}

Christian



More information about the Python-3000 mailing list