python3的等价物是什么sys.stdout.fileno文件号()在Python 2中

2024-06-06 19:09:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在用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实现这一点?你知道吗


Tags: to代码pythonapionstdoutsyslibrarydo
1条回答
网友
1楼 · 发布于 2024-06-06 19:09:28

问题是系统标准输出被FlushingStringIO替换为库:https://github.com/flexible-atomic-code/fac。它也在某种程度上取决于这个细节,否则就会中断。由于没有合理的库替代方案,因此在这种情况下无法抑制标准输出。你知道吗

相关问题 更多 >