我正在用python2.7编写代码。我使用了一个非常特殊的库,部分用C编写,带有pythonapi。这个库使用printf输出到stdout。我想压制一下。我已经发现这个问题:How do I prevent a C shared library to print on stdout in python?所有提供的答案都使用sys.stdout.fileno文件号()。当我运行代码时,我得到:
original_stdout_fd = sys.stdout.fileno()
AttributeError: 'FlushingStringIO' object has no attribute 'fileno'
我怀疑问题是我使用的是Python2.7。我的假设正确吗?有没有一种方法可以通过Python2.7实现这一点?你知道吗
问题是系统标准输出被FlushingStringIO替换为库:https://github.com/flexible-atomic-code/fac。它也在某种程度上取决于这个细节,否则就会中断。由于没有合理的库替代方案,因此在这种情况下无法抑制标准输出。你知道吗
相关问题 更多 >
编程相关推荐