作家
登录

Python调用C模块以及性能分析

作者: 来源: 2017-07-13 14:05:08 阅读 我要评论

  •  
  • ...     _fields_=[('x',c_int),('y',c_int)] 
  •  
  • ... 
  •  
  • >>> point=POINT(2,4) 
  •  
  • >>> point 
  •  
  • <__main__.POINT object at 0x7f7be1983b90> 
  •  
  • >>> point.x,point.y 
  •  
  • (2, 4) 
  •  
  • >>> porint=POINT(y=2) 
  •  
  • >>> porint 
  •  
  • <__main__.POINT object at 0x7f7be1983cb0> 
  •  
  • >>> point=POINT(y=2) 
  •  
  • >>> point.x,point.y 
  •  
  • (0, 2) 
  •  
  • 定义一个类型为POINT的数组 
  •  
  • >>> POINT_ARRAY=POINT*3 
  •  
  • >>> pa=POINT_ARRAY(POINT(2,3),POINT(2,4),POINT(2,5)) 
  •  
  • >>> for i in pa:print pa.y 
  •  
  • ... 
  •  
  • Traceback (most recent call last): 
  •  
  •   File "<stdin>", line 1, in <module> 
  •  
  • AttributeError: 'POINT_Array_3' object has no attribute 'y' 
  •  
  • >>> for i in pa:print i.y 
  •  
  • ... 
  •  
  •  
  •  
  •  
  • 6.拜访so文件

    1. #include <stdio.h> 
    2.  
    3. int hello_world(){ 
    4.  
    5.     printf("Hello World\n"); 
    6.  
    7.     return 0; 
    8.  
    9.  
    10. int main(){ 
    11.  
    12.         hello_world(); 
    13.  
    14.         return 0; 
    15.  
    16.  

    2.编译成动态链接库

    1. gcc hello_world.c  -fPIC -shared -o hello_world.so 

    3.python中调用库中的函数

    1. from ctypes import cdll 
    2.  

    3.   推荐阅读

        爱加密与安百科技深度“联姻” 共同消弭企业“安全孤岛”

      平顺家当涵盖的范畴异常广泛,固然每个细分市场都有“头牌”,但并没有某一家安然巨擘有底气传播鼓>>>详细阅读


      本文标题:Python调用C模块以及性能分析

      地址:http://www.17bianji.com/lsqh/36195.html

    关键词: 探索发现

    乐购科技部分新闻及文章转载自互联网,供读者交流和学习,若有涉及作者版权等问题请及时与我们联系,以便更正、删除或按规定办理。感谢所有提供资讯的网站,欢迎各类媒体与乐购科技进行文章共享合作。

    网友点评
    自媒体专栏

    评论

    热度

    精彩导读
    栏目ID=71的表不存在(操作类型=0)