Cython学习日记1

1.Cython预定义编译时名字
解析:
(1)UNAME_SYSNAME:Operating system name
(2)UNAME_RELEASE:Operating system release
(3)UNAME_VERSION:Operating system version
(4)UNAME_MACHINE:Machine hardware name
(5)UNAME_NODENAME:Name on network

2.Cython中DEF常量,函数和类型
解析:
(1)常量:None,True,False。
(2)内置函数:abs,chr,cmp,divmod,enumerate,hash,hex,len,map,max,min,oct,ord,pow,range,reduce,repr,round,sum,xrange,zip。
(3)内置类型:bool,complex,dict,float,int,list,long,slice,str,tuple。

3.C++和Python异常映射
解析:
(1)bad_alloc:MemoryError
(2)bad_cast:TypeError
(3)domain_error:ValueError
(4)invalid_argument:ValueError
(5)ios_base::failure:IOError
(6)out_of_range:IndexError
(7)overflow_error:OverflowError
(8)range_error:ArithmeticError
(9)underflow_error:ArithmeticError
(10)All others:RuntimeError

4.Python到C++容器
解析:
(1)bytes,str,unicode:string
(2)mapping (dict):map,unordered_map
(3)iterable:set,unordered_set
(4)iterable:vector,list
(5)length two iterable:pair

5.C++到Python容器
解析:
(1)string:bytes,str,unicode
(2)map,unordered_map:dict
(3)set,unordered_set:set
(4)vector,list:list
(5)pair:tuple

6.Python源码目录结构
解析:
(1)Include:该目录下包含了Python提供的所有头文件,如果用户需要自己用C或C++来编写自定义模块扩展Python,那么就需要用到这里提供的头文件。
(2)Lib:该目录包含了Python自带的所有标准库,Lib中的库都是用Python语言编写的。
(3)Modules:该目录中包含了所有用C语言编写的模块,比如random、cStringIO等。Modules中的模块是那些对速度要求非常严格的模块,而有一些对速度没有太严格要求的模块,比如os,就是用Python编写的,并且放在Lib目录下。
(4)Parser:该目录中包含了Python解释器中的Scanner和Parser部分,即对Python源代码进行词法分析和语法分析的部分。除了这些,Parser目录下还包含了一些有用的工具,这些工具能够根据Python语言的语法自动生成Python语言的词法和语法分析器,与YACC非常类似。
(5)Objects:该目录下包含了所有Python的内建对象,包括整数、list、dict等。同时,该目录还包含了Python在运行时需要的所有的内部使用对象的实现。
(6)Python:该目录下包含了Python解释器中的Compiler和执行引擎部分,是Python运行的核心所在。
(7)PCBuild:包含了Visual Studio的工程文件,研究Python源代码就从这里开始。

7.__builtin____builtins__和builtins
解析:
在Python 2.X中,内建模块为__builtin__,而在Python 3.X中,内建模块为builtins。__builtins__同时存在于Python 2.X和Python 3.X中,它是对内建模块的一个引用。如下所示:
(1)在__main__中,__builtins__是对内建模块__builtin__本身的引用,两者完全等价。
(2)在非__main__中,__builtins__仅是对__builtin__.__dict__的引用,而非__builtin__本身。

8.Python中的__bases__属性
解析:在Python中,每个类有一个bases属性,列出其基类。

9.<type 'type'>
解析:<type 'type'>是Python内部的PyType_Type,它是所有class的class,所以它在Python中被称为metaclass。

10.Python的7种性能测试工具
解析:timeit、profile、cProfile、line_profiler、memory_profiler、PyCharm图形化性能测试工具、objgraph。

11.cdef和cpdef区别

12.pyximport
解析:pyximport可以在import一个pyx文件时动态对其进行编译。由于这种方法依赖于cython和gcc,因此不适合应用在生产系统上。

13.memoryview()函数
解析:memoryview()函数返回给定参数的内存查看对象(Momory view)。所谓内存查看对象,是指对支持缓冲区协议的数据进行包装,在不需要复制对象基础上允许Python代码访问。

14.cimport
解析:Sharing Declarations Between Cython Modules:https://cython.readthedocs.io/en/latest/src/userguide/sharing_declarations.html

15.python-config [–prefix][–exec-prefix][–includes][–libs][–cflags][–ldflags][–help]
解析:
(1)–cflags:print the C compiler flags.
(2)–ldflags:print the flags that should be passed to the linker.
(3)–includes:similar to –cflags but only with -I options (path to python header files).
(4)–libs:similar to –ldflags but only with -l options (used libraries).
(5)–prefix:prints the prefix (base directory) under which python can be found.
(6)–exec-prefix:print the prefix used for executable program directories (such as bin, sbin, etc).
(7)–help print the usage message.

16.反汇编和反编译区别
解析:反汇编得到的是汇编代码,反编译得到的是所用语言的源代码。

参考文献:
[1]Python中decorator的用法及原理:http://blog.csdn.net/u013696062/article/details/51065406
[2]Python的7种性能测试工具:http://blog.csdn.net/xiemanr/article/details/72763234
[3]利用PyCharm的Profile工具进行Python性能分析:http://blog.csdn.net/xiemanr/article/details/69398057
[4]Cobra对Python源文件进行完整反汇编:http://blog.csdn.net/balabalamerobert/article/details/1672568

猜你喜欢

转载自blog.csdn.net/shengshengwang/article/details/79138440