【发布时间】:2015-10-19 11:09:57
【问题描述】:
我想将 pycosat 的详细输出存储到一个字符串中:
import pycosat
cnf = [[1, -5, 4], [-1, 5, 3, 4], [-3, -4]]
pycosat.solve(cnf,verbose=5)
我找到了各种解决方案,例如 Capture stdout from a script in Python
但是,基于 stringIO() 的解决方案不会捕获 pycosat 输出。输出正常打印,并捕获一个空字符串。
我认为这与 pycosat 绑定到 c-library picosat 的事实有关,但我不知道如何处理。
此解决方案也不起作用 https://stackoverflow.com/a/29834357/4270148
Python 将冻结在
out.stop()
ipython 也会冻结在
sys.stdout = StringIO()
这可能与它有关。
我没有尝试使用使用子进程的解决方案,因为我需要局部变量cnf,将它传递给子进程并没有什么意义。
我不知道它是否应该相关,但我在 osx-64 上使用 conda 3.14.1
【问题讨论】:
-
你确实在 Mac OS X 内置的 Python 上试过了,对吧?
-
我没有,因为我没有在那里安装 pycosat(由于包问题我使用 conda)
标签: python c printing binding output