why does sys.stdout = None work?

后端 未结 1 1673
自闭症患者
自闭症患者 2020-12-10 15:14

i can silence and restore sys.stdout this way:

import sys
sys.stdout = None
print(\'hello\')  # does not write to stdout
sys.stdout = sys.__stdo         


        
相关标签:
1条回答
  • 2020-12-10 16:06

    print has an explicit check for None.

        /* sys.stdout may be None when FILE* stdout isn't connected */
        if (file == Py_None)
            Py_RETURN_NONE;
    
    0 讨论(0)
提交回复
热议问题