Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fef9bba

Browse files
committed
Another #1415 fix for Windows GUI apps
print() mustn't raise an exception when sys.stdout is None.
1 parent db23308 commit fef9bba

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

Python/bltinmodule.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,9 +1192,13 @@ builtin_print(PyObject *self, PyObject *args, PyObject *kwds)
11921192
}
11931193
if (!PyArg_ParseTupleAndKeywords(dummy_args, kwds, "|OOO:print",
11941194
kwlist, &sep, &end, &file))
1195-
return NULL;
1196-
if (file == NULL || file == Py_None)
1195+
return NULL;
1196+
if (file == NULL || file == Py_None) {
11971197
file = PySys_GetObject("stdout");
1198+
/* sys.stdout may be None when FILE* stdout isn't connected */
1199+
if (file == Py_None)
1200+
Py_RETURN_NONE;
1201+
}
11981202

11991203
if (sep && sep != Py_None && !PyUnicode_Check(sep)) {
12001204
PyErr_Format(PyExc_TypeError,

0 commit comments

Comments
 (0)