summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2012-01-13 18:41:25 (GMT)
committerGeorg Brandl <georg@python.org>2012-01-13 18:41:25 (GMT)
commitbc3b682923a22b89b0f5462ee2e807a4cc4ea81d (patch)
treed9842f6dfe5185783fe797d62c2e8e43efdff593 /Python
parent5136ac0ca21a05691978df8d0650f902c8ca3463 (diff)
downloadcpython-bc3b682923a22b89b0f5462ee2e807a4cc4ea81d.zip
cpython-bc3b682923a22b89b0f5462ee2e807a4cc4ea81d.tar.gz
cpython-bc3b682923a22b89b0f5462ee2e807a4cc4ea81d.tar.bz2
Closes #13761: add a "flush" keyword argument to print().
Diffstat (limited to 'Python')
-rw-r--r--Python/bltinmodule.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index d1630cc..81402fc 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -1484,15 +1484,15 @@ equivalent to (x**y) % z, but may be more efficient (e.g. for longs).");
static PyObject *
builtin_print(PyObject *self, PyObject *args, PyObject *kwds)
{
- static char *kwlist[] = {"sep", "end", "file", 0};
+ static char *kwlist[] = {"sep", "end", "file", "flush", 0};
static PyObject *dummy_args;
- PyObject *sep = NULL, *end = NULL, *file = NULL;
+ PyObject *sep = NULL, *end = NULL, *file = NULL, *flush = NULL;
int i, err;
if (dummy_args == NULL && !(dummy_args = PyTuple_New(0)))
- return NULL;
- if (!PyArg_ParseTupleAndKeywords(dummy_args, kwds, "|OOO:print",
- kwlist, &sep, &end, &file))
+ return NULL;
+ if (!PyArg_ParseTupleAndKeywords(dummy_args, kwds, "|OOOO:print",
+ kwlist, &sep, &end, &file, &flush))
return NULL;
if (file == NULL || file == Py_None) {
file = PySys_GetObject("stdout");
@@ -1543,6 +1543,20 @@ builtin_print(PyObject *self, PyObject *args, PyObject *kwds)
if (err)
return NULL;
+ if (flush != NULL) {
+ PyObject *tmp;
+ int do_flush = PyObject_IsTrue(flush);
+ if (do_flush == -1)
+ return NULL;
+ else if (do_flush) {
+ tmp = PyObject_CallMethod(file, "flush", "");
+ if (tmp == NULL)
+ return NULL;
+ else
+ Py_DECREF(tmp);
+ }
+ }
+
Py_RETURN_NONE;
}