源代码如下:

参数 -O :混淆所有函数/方法名、变量和类。默认是不要混淆。

我这里使用参数 -O 进行源码混淆。

如果运行时报错:UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position 54: illegal multibyte sequence
可以查看解决方法:
Python 技术篇 - 修改 pyminifier 库源码解决编码不一致导致的报错问题

转换后生成新文件,minified 文件夹里也是转化后的内容,这个是默认生成的,通过参数 -d 可以进行指定。

可以看到方法和变量名都被改了,而且注释也被默认去掉了,这样就一定程度上提高了我们源代码的安全性。
当然默认会被编码为 gbk ,如需调整可以自行转化一下文件编码。

pyminifier 详细命令方法如下:

pyminifier -h
Usage: pyminifier [options] "<input file>"Options:--version             show program's version number and exit-h, --help            show this help message and exit-o <file path>, --outfile=<file path>Save output to the given file.-d <file path>, --destdir=<file path>Save output to the given directory. This option isrequired when handling multiple files. Defaults to'./minified' and will be created if not present.将输出保存到给定的目录。当处理多个文件时,此选项是必需的。默认为'./minified',如果不存在,将被创建。--nominify            Don't bother minifying (only used with --pyz).--use-tabs            Use tabs for indentation instead of spaces.使用制表符代替空格来缩进。--bzip2               bzip2-compress the result into a self-executing pythonscript.  Only works on stand-alone scripts withoutimplicit imports.以bzip2方式压缩将结果到一个自动执行的python脚本中。只能在独立脚本上工作,不需要隐式导入。--gzip                gzip-compress the result into a self-executing pythonscript.  Only works on stand-alone scripts withoutimplicit imports.以gzip方式压缩结果到一个自执行的python脚本中。只能在独立脚本上工作,不需要隐式导入。--lzma                lzma-compress the result into a self-executing pythonscript.  Only works on stand-alone scripts withoutimplicit imports.以lzma方式压缩将结果到一个自动执行的python脚本中。只能在独立脚本上工作,不需要隐式导入。--pyz=<name of archive>.pyzzip-compress the result into a self-executing pythonscript. This will create a new file that includes anynecessary implicit (local to the script) modules.Will include/process all files given as arguments topyminifier.py on the command line.-O, --obfuscate       Obfuscate all function/method names, variables, andclasses.  Default is to NOT obfuscate.--obfuscate-classes   Obfuscate class names.--obfuscate-functionsObfuscate function and method names.--obfuscate-variablesObfuscate variable names.--obfuscate-import-methodsObfuscate globally-imported mouled methods (e.g.'Ag=re.compile').--obfuscate-builtins  Obfuscate built-ins (i.e. True, False, object,Exception, etc).--replacement-length=1The length of the random names that will be used whenobfuscating identifiers.--nonlatin            Use non-latin (unicode) characters in obfuscation(Python 3 only).  WARNING: This results in someSERIOUSLY hard-to-read code.--prepend=<file path>Prepend the text in this file to the top of ouroutput.  e.g. A copyright notice.

喜欢的点个赞❤吧!

Python 技术篇 - 通过pyminifier库实现源码压缩、混淆、加密保护实例演示,pyminifier的使用方法相关推荐

  1. Python 技术篇-用PIL库实现等比例压缩、缩小图片实例演示

    PIL 库安装直接pip install pillow就好了 PIL 库的 resize() 方法可以修改图片尺寸,里面的参数需要整数,所以我用 int 转化了一下. 等比例就是通过 size 属性获 ...

  2. Python 技术篇-用paramiko库实现linux服务器文件下载到winodws本地实例演示

    如果需要上传文件的话,可以看这篇文章: Python 技术篇-用 paramiko 库实现 winodws 本地文件上传至 linux 服务器实例演示 # -*- coding: UTF8 -*- i ...

  3. Python 技术篇-socket套接字实现两个窗口间消息传递实例演示,TCP实现

    上一篇:Python 技术篇-socket 套接字实现服务器客户端消息传递,UDP 实现 本篇介绍用 TCP 来实现. socket 实现客户端服务器的消息传递有 TCP 和 UDP 两种方式. TC ...

  4. Python 技术篇-在cmd命令提示行里模拟动态下载进度条实例演示,cmd清除日志、打印动态内容方法

    模拟进度条的核心就是用 os.system('cls') 不断的来清除屏幕之前的数据,再打印出新的,给人一种动态的感觉. # -*- coding: UTF8 -*- import os import ...

  5. 精选合辑 | 30个Python数据分析及实战项目(含源码)

    今天给大家推荐一个优质的Python公众号「法纳斯特」,作者:小F. 小F是211机械专业毕业的,上学的时候还造了两辆车(FSC.无碳小车),毕业以后又在车企搬了一年的砖,最终决定转行IT,从零开始学 ...

  6. print python 带回车_python标准库threading源码解读【二】

    紧接着上一篇文章继续解析源码 甘蔗:python标准库threading源码解读[一]​zhuanlan.zhihu.com 目录 Event的介绍和用法 Event源码解析 以后的内容尽量少一点并且 ...

  7. python库源码分析_python第三方库Faker源码解读

    源码背景 Faker是一个Python第三方库,GITHUB开源项目,主要用于创建伪数据创建的数据包含地理信息类.基础信息类.个人账户信息类.网络基础信息类.浏览器信息类.文件信息类.数字类 文本加密 ...

  8. essential c++源码_Goldenmask - 一键化保护你的 Python 源码

    项目地址: https://github.com/youngquan/goldenmask​github.com Goldenmask 直译为金色的罩子,灵感来自"金钟罩"的&qu ...

  9. Python concurrent.future 使用教程及源码初剖

    前言 原文发在这里的 Python concurrent.future 使用教程及源码初剖 垃圾话 很久没写博客了,想了想不能再划水,于是给自己定了一个目标,写点 concurrent.future ...

最新文章

  1. linux监测cpu 内存,Linux中CPU与内存性能监测.docx
  2. 前端每周清单第 50 期: AngularJS and Long Term Support, Web 安全二三论
  3. 分布式查询的使用准则
  4. GDI+绘制极坐标图(Polar Diagram)
  5. Elasticsearch filter和query的不同
  6. python扫描ip的端口打开情况
  7. 菜鸟裹裹电脑版_【绵阳最新转让】3500低价出售家用制氧机!东芝i5笔记本电脑、索尼微单相机、联想笔记本电脑、奶茶店、服装店转让......
  8. mysql null 0 空_MySQL中 null与not null和null与空值''的区别
  9. iview在项目中遇到的坑
  10. day25 在继承的背景下属性查找的顺序、组合、多态与接口、鸭子类型
  11. 传智播客java测试题_传智播客java测试题
  12. 图像几何运算——Matlab实现
  13. pandas中DataFrame如何检测重复值
  14. Linux user 的密码策略设定 /etc/shadow
  15. Python判断html的元素,python判断网页元素是否存在的方法
  16. MAVEN(一)——配置以及plugins
  17. android app 内嵌h5小游戏
  18. 用Java自动发邮件
  19. Java 中this和super的用法总结
  20. OLED_I2C_3D_Cube

热门文章

  1. 201521123108《Java程序设计》第14周学习总结
  2. Spanner——Google的全球化分布式数据库
  3. 抽象SQL查询:SQL-MAP技术的使用
  4. 【转】 ASP.NET 3.5中使用新的ListView控件
  5. 开始使用VS2005+ASP.NET+Access(以后可能是MS SQL Server)编写管理系统的计划
  6. Flutter RichText支持自定义文本溢出效果
  7. char,Character,int,字符及编码日记 1
  8. windows命名管道
  9. 正则表达式(2.实例)
  10. MATLAB - 为什么imshow(g,[])可以正常显示,而imshow(g)却显示空白图像?