Python 文件编译为字节码的方法

Posted Anonymous

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python 文件编译为字节码的方法相关的知识,希望对你有一定的参考价值。

 

一般情况下 python 不需要手动编译字节码。但是如果不想直接 release 源代码给其他人,将文件编译成字节码,可以实现一定程度的信息隐藏。

 

1) 使用模块 py_compile 编译一个单文件

import py_compile
py_compile.compile(./demo.py)

2) 使用模块 compileall 递归的编译一个文件包

import compileall
compileall.compile_dir(./test)

3) 使用模块 compileall 编译一个单文件

import compileall
compileall.compile_file(./demo.py)

 

更多应用请详细阅读这两个模块的帮助文件。

 

完。

 

以上是关于Python 文件编译为字节码的方法的主要内容,如果未能解决你的问题,请参考以下文章