9. Python与C之导入变量
2019-11-25 18:18
204 查看
-
通过对应类型的类方法
in_dll
的方式来加载。struct Test { int a; int b; Test(int x=5,int y = 6):a(x),b(y){} }; extern "C" int hello = 1; extern "C" int * hellop = &hello; extern "C" Test t(1,2); extern "C" void show() { hello = 10; }
from ctypes import * class Test(Structure): _fields_ = [ ("a",c_int),("b",c_int)] handle = CDLL("./test.so") hello = c_int.in_dll(handle,"hello") hellop = POINTER(c_int).in_dll(handle,"hellop") ttest = Test.in_dll(handle,"t") handle.show() print(hello,hellop[0],ttest.a,ttest.b)
-
编译执行
g++ -m32 -shared -fPIC -o test.so test.cpp
python test.py
相关文章推荐
- [Python学习] 专题六.局部变量、全局变量global、导入模块变量
- [Python学习] 专题六.局部变量、全局变量global、导入模块变量
- python 环境变量和import模块导入方法(详解)
- python tips:导入变量不能以_打头
- Python 专题六 局部变量、全局变量global、导入模块变量
- python pickle导入numpy变量出错: "ImportError: No module named multiarray"
- Python 导入模块是变量名时如何导入
- python模块导入,环境变量
- python_基础总结1 python由来 字符编码 注释 pyc文件 python变量 导入模块 获取用户输入 流程控制if while
- 把Python安装路径导入到系统环境变量中
- Python笔记第1章,流程控制,用户交互,语法要求,变量,字符,注释,模块导入的使用
- Centos6 python3 导入第三方函数库,自定义函数库的几种配置方法(sys.path, PYTHONPATH, .pth, 环境变量)
- python改变导入模块中的变量的问题
- django python 中模块的变量导入
- Python基础:数据类型、变量定义、输入/输出、逻辑、函数/模块(导入)/类、异常处理
- 对Python模块导入时全局变量__all__的作用详解
- python环境变量和import模块导入方法
- Python _X __all__ 模拟 导入'私有'变量 及其注意点和实例
- python3 动态模块导入与全局变量使用
- PyGrADS可以很方便地将GrADS中的变量导入Python内存空间