如何从Python中使用的C库中抑制tprintf

如何从Python中使用的C库中抑制tprintf,python,c,cython,tesseract,Python,C,Cython,Tesseract,我正在使用Python代码中的C库(tesseract)。C库中的打印显示在我的python程序的标准输出中: tprintf("Too few characters. Skipping this page\n"); 在使用python中的C库时,有没有办法抑制这些打印语句?我已经尝试了一种我在SO上找到的方法,但它没有帮助。它确实抑制了打印“test”,但是,它不抑制来自C库中tprintf的输出 我试过这个方法,但不起作用。我仍然可以在标准输出上看到输出 devnull = open('/

我正在使用Python代码中的C库(tesseract)。C库中的打印显示在我的python程序的标准输出中:

tprintf("Too few characters. Skipping this page\n");
在使用python中的C库时,有没有办法抑制这些打印语句?我已经尝试了一种我在SO上找到的方法,但它没有帮助。它确实抑制了
打印“test”
,但是,它不抑制来自C库中
tprintf
的输出

我试过这个方法,但不起作用。我仍然可以在标准输出上看到输出

devnull = open('/dev/null', 'w')
oldstdout_fno = os.dup(sys.stdout.fileno())
os.dup2(devnull.fileno(), 1)

tesseract = ctypes.cdll.LoadLibrary("/path/to/tesseract.so")
api = tesseract.TessBaseAPICreate()
rc = tesseract.TessBaseAPIInit3(api, TESSDATA_PREFIX, "osd")
tesseract.TessBaseAPISetPageSegMode(api, 1) #this line prints "Too few characters. Skipping this page" to stdout

os.dup2(oldstdout_fno, 1)

这看起来很相关:(srderr,不是stdout,而是指定输出到文件的选项)您可以设置Tesseract变量,例如:
api.setVariable(“debug_file”,“dev/null”)请参阅。