Use the compileall module in Pyhthon to compile the source file as a pyc file.
This article mainly introduces how to use the compileall module in Pyhthon to compile the source file as a pyc file. For more information, see
Sometimes we need to put the project. all python source files of py are compiled. pyc file, retain only. the pyc file is then published to others (though decompiled, it is also a type of protection ).
At this time, you can use the compileall library to do this. It can recursively compile all. py files in a folder into. pyc files.
For example, if I have a django project in the test folder
The Code is as follows:
E: \> python-c "import compileall; import re; compileall. compile_dir ('test', rx = re. compile (R' [/\] [.] svn '), force = True )"
For more usage and parameters, see
Http://pymotw.com/2/compileall/
Https://docs.python.org/2/library/compileall.html
Then delete the. py file and keep the. pyc file.
In linux, you can directly use the find command. In windows, you can use the doscommand and write a python script to delete these files.