[英]How to access functions in a C++ dll from python ,all I have is a package(a header file and a dll file)
[英]How to access c++ header file in python files(.py)
我從 c++ 頭文件導入到 python .py 文件中。我可以訪問 c++ 頭文件 #define 到 python
在python代碼中,
import sys
sys.path.import
我期望在運行 python 代碼時 #define 的值它得到名稱錯誤
您不能只是import
C++ 標頭導入 Python 程序 - 它們是不同的語言,因此無法正常工作。 它比這復雜得多,請參閱使用 C 或 C++ 擴展 Python 。
如果您只想從 C++ 頭文件中挑選#define
,可以簡單地在 Python 程序中打開該文件並搜索以#define
開頭的行並解析變量和值。 就像是:
import re
defines = {}
with open("header_file.h") as header_file:
for line in header_file.readlines():
if line.startswith("#define"):
line.rstrip()
m = re.search('#define\s+([A-Za-z]\w+)\s+(.*)', line)
if m:
defines[m.group(1)] = m.group(2)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.