python __debug__与sys.path_hooks

来源:互联网 发布:cdn和云计算 编辑:程序博客网 时间:2024/05/16 14:51
__debug__

This constant is true if Python was not started with an -O option.See also theassert statement.

Note

The names None and __debug__ cannot be reassigned(assignments to them, even as an attribute name, raiseSyntaxError),so they can be considered “true” constants.

Changed in version 2.7:Assignments to__debug__ as an attribute became illegal.



__debug__默认都是True的,除非设置了-O选项


-O

Turn on basic optimizations. This changes the filename extension forcompiled (bytecode) files from .pyc to .pyo. See alsoPYTHONOPTIMIZE.


sys.path_hooks

用来hook import是的路径

一般代码打包后,例如放到一个.script后缀文件里面,可以自定义一个类,hook住,这样可以对代码加密等一类的处理

0 0