如何在python文件中访问c ++头文件(.py)
How to access c++ header file in python files(.py)
我正在从 c++ 头文件导入 python .py 文件.我可以访问 c++ 头文件 #define 到 python 中
吗?在 python 代码中,
import sys
sys.path.import
我期望 #define 在运行 python 代码中的价值它得到名称错误
你不能
只是将C++头import
到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('#defines+([A-Za-z]w+)s+(.*)', line)
if m:
defines[m.group(1)] = m.group(2)
相关文章:
- .cpp和.h文件中的模板专用化声明
- 为什么两个不同的未命名名称空间可以共存于一个cpp文件中
- 文本文件中的单词链表
- CMake-按正确顺序将项目与C运行时对象文件链接
- 使用新行和不使用新行读取文件
- 在C++程序中输入的文本文件将不起作用,除非文本被复制和粘贴
- 挂起和取消挂起一个文件DLL
- 如何确定我已使用非编码文件到达 EOF?
- 命名空间中具有.h和.cpp文件的类
- 如何使用ndk-build.cmd构建Android.so文件
- 从包含m行的文件中提取n行,必要时(惰性地)重复该文件
- pybind11:属性错误:尝试从 py 文件运行函数时,模块'XXX'没有属性'YYY'
- 如何从 python (py) 文件调用 C++ 函数
- 如何在python文件中访问c ++头文件(.py)
- 提升 Python 如何在导入的 Python 文件中导入 py
- 从 C++ 执行.py文件
- 如何在多个项目(以及一个版本的 cpplint.py)中使用单个生成文件
- 动态库在添加到setup.py文件(在MacOS.X上)时会导致错误
- cpplint.py & cmake:如何指定包含文件
- 在生成的.py文件中添加注释