专栏名称: Python学习交流
每天更新,更新python相关的知识。希望诸君有所收获!
目录
相关文章推荐
Python开发者  ·  三大云厂同时瘫了?Cursor、ChatGP ... ·  22 小时前  
Python初级入门到精通  ·  Python-finally语句与应用 ·  昨天  
Python爱好者社区  ·  90W,确实可以封神了! ·  4 天前  
Python爱好者社区  ·  北大“韦神”粉丝超千万,家属回应牙齿缺失 ·  4 天前  
51好读  ›  专栏  ›  Python学习交流

Python与C混合编程!是Python和C都不具备的超能力!

Python学习交流  · 公众号  · Python  · 2018-12-17 14:43

正文

请到「今天看啥」查看全文



v->push_back(i);
}
}

编译: gcc -fPIC -shared -lpython3.6m -o vector_py.so vectory_py.c


编写 ctypes 类型文件

from ctypes import *
class c_point_t(Structure):
_fields_ = [("x", c_int), ("y", c_int)]
class Vector(object):
lib = cdll.LoadLibrary('./vector_py_lib.so') # class level loading lib
lib.new_vector.restype = c_void_p
lib.new_vector.argtypes = []
lib.delete_vector.restype = None
lib.delete_vector.argtypes = [c_void_p]
lib.vector_size.restype = c_int
lib.vector_size.argtypes = [c_void_p]
lib.vector_get.restype = c_point_t
lib.vector_get.argtypes = [c_void_p, c_int]
lib.vector_push_back.restype = None
lib.vector_push_back.argtypes = [c_void_p, c_point_t]






请到「今天看啥」查看全文