Pyhthon中使用compileall模块编译源文件为pyc文件
有的时候我们需要把项目中.py的python所有源文件编译成.pyc文件,只保留.pyc文件然后发布给别人(虽然说可以反编译,但也算是一种保护把).
这个时候就可以使用compileall 库来完成这个工作,它可以递归的把一个文件夹下的所有.py文件编译成.pyc文件。
例如我有一个django项目在test文件夹下就可以
E:\>python -c "import compileall; import re; compileall.compile_dir('test', rx=re.compile(r'[/\\][.]svn'), force=True)"
更多的使用和参数请参考
http://pymotw.com/2/compileall/
https://docs.python.org/2/library/compileall.html
然后就是要删除.py文件保留.pyc 文件了。
在linux下可以直接使用 find命令,在windows下可以使用dos命令,还可以写一个python脚本删除这些文件

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Solution to permission issues when viewing Python version in Linux terminal When you try to view Python version in Linux terminal, enter python...

How to avoid being detected when using FiddlerEverywhere for man-in-the-middle readings When you use FiddlerEverywhere...

How to teach computer novice programming basics within 10 hours? If you only have 10 hours to teach computer novice some programming knowledge, what would you choose to teach...

When using Python's pandas library, how to copy whole columns between two DataFrames with different structures is a common problem. Suppose we have two Dats...

How does Uvicorn continuously listen for HTTP requests? Uvicorn is a lightweight web server based on ASGI. One of its core functions is to listen for HTTP requests and proceed...

Fastapi ...

Using python in Linux terminal...

Understanding the anti-crawling strategy of Investing.com Many people often try to crawl news data from Investing.com (https://cn.investing.com/news/latest-news)...
