我寫了一個簡單的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
不會按預期重定向。請幫我解決這個問題。謝謝。