【发布时间】:2010-04-10 13:17:51
【问题描述】:
我想将 python 中的值传递给 c++ 程序,以便从 python 程序内部进行加密,然后将值从那里返回给 python 程序。怎么办?
【问题讨论】:
我想将 python 中的值传递给 c++ 程序,以便从 python 程序内部进行加密,然后将值从那里返回给 python 程序。怎么办?
【问题讨论】:
如果你想使用一些现有的 Unix 风格的命令行实用程序,从标准输入读取并写入标准输出,你可以通过 Popen.communicate() 使用 subprocess.Popen:
import subprocess
p = subprocess.Popen(["/your/app"], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
output = p.communicate(input)[0]
【讨论】:
正如 msw 在另一篇文章中所说,正确的解决方案是使用 PyObject。 如果你想在 C++ 和 Python 之间进行双向通信,那么 Boost Python 对你来说会很有趣。看看网站Boost Python,
这篇文章也很有趣: How to expose a C++ class to Python without building a module
【讨论】: