Use the compileall module in Pyhthon to compile the source file as a pyc file.

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.