我写了一个简单的C模块打印到标准输出使用printf。问题重定向标准输出的Python函数stdout
// sample.c
func_print()
{
printf("Hello World!\n");
}
后来,我做了这周围的包装使用SWIG
,这样我可以用我的Python程序func_print
了。在这个程序中,我将stdout重定向到了一个textctrl小部件。正如预期的那样,我使用print
打印的任何内容都可以在textctrl小部件中正确打印。
# sample.py
...
sys.stdout = textctrl # textctrl is a TextCtrl widget (wxPython).
print 'Hello from Python!' # prints in the textctrl widget, as expected.
然而,当我调用C函数func_print()
(来自sample.py),其打印到终端而不是textctrl部件。
func_print() # [Problem] prints to the terminal window, instead of the textctrl widget.
不知怎的,似乎对C模块中的功能stdout
不会按预期重定向。请帮我解决这个问题。谢谢。