<强>这篇文章主要介绍了如何基于python实现
脚本加密,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下强>
<>之前得到pathlib import 路径
import python_minifier
import compileall
import 系统
,
def get_save_path (from_dir, to_dir,, p):
ori_dir 才能=,str (from_dir.resolve ())
_p 才能=,str (p.resolve ())
return 才能;to_dir.joinpath (_p.split (ori_dir) [1] [1:])
def mix_pyminifier (from_dir, to_dir):
for 才能;_p 拷贝from_dir.rglob (& # 39; * . py # 39;):
,,,with _p.open(编码=& # 39;utf - 8 # 39;), as read_fp:
,,,,,res =, python_minifier.minify (read_fp.read ())
,
,,,_to_p =, get_save_path (from_dir, to_dir,, _p)
,,,的路径(_to_p.parent) .mkdir (exist_ok=True,,父母=True)
,,,with _to_p.open (& # 39; w # 39;,,编码=& # 39;utf - 8 # 39;), as write_fp:
,,,,,write_fp.write (res)
,
,
def py2pyc (from_dir, to_dir):
compileall.compile_dir才能(str (from_dir.resolve ()),, maxlevels=20,,=True)
def pyc2py (from_dir, to_dir):
,通过
if __name__ ==, & # 39; __main__ # 39;:
时间=origin_dir 才能;路径(sys.argv [1])
时间=target_dir 才能;路径(sys.argv [2])
pymini_dir 才能=,target_dir.joinpath (& # 39; pymini& # 39;)
pyc_dir 才能=,target_dir.joinpath (& # 39; pyc_dir& # 39;)
py_dir 才能=,target_dir.joinpath (& # 39; py_dir& # 39;)
mix_pyminifier才能(origin_dir, target_dir)
#,才能py2pyc (origin_dir, pyc_dir)
#,才能pyc2py (pyc_dir, pyc_dir)
以上就是本文的全部内容,希望对大家的学习有所帮助。
原文地址: https://www.linuxprobe.com/linux-python-compileall.html