https://my.oschina.net/wizardpisces/blog/107445
https://www.cnblogs.com/kaituorensheng/p/4501128.html
http://help.sense.com.cn/?p=165
http://www.cnblogs.com/haq5201314/p/8437201.htmlhtml
将python文件.py编译成pyc二进制文件:python
python -m py_file.py
或者经过脚本运行:优化
import py_compile ##单个文件编译 import compileall ##多个文件编译 py_compile.compile('path') ##path是包括.py文件名的路径
将python文件编译成pyo二进制文件:加密
python -O -m py_file.py
什么是pyc文件?spa
pyc是一种二进制文件,是由py文件通过编译后,生成的文件,是一种byte code,py文件变成pyc文件后,加载的速度有所提升,并且pyc是一种跨平台的字节码,是由python的虚拟机来执行的,这个是相似于JAVA或者.NET的虚拟机的概念。.net
注意事项:pyc的内容,是跟python的版本相关的,不一样版本编译后的pyc文件是不一样的,2.5编译的pyc文件,2.4版本的 python是没法执行的。code
什么是pyo文件?server
pyo是优化编译后的程序 python -O 源文件便可将源程序编译为pyo文件 htm
什么是pyd文件?blog
pyd是python的动态连接库。
参考:https://blog.csdn.net/SoaringLee_fighting/article/details/78892876
hashlib模块:
import hashlib sha1 = hashlib.sha1('文本内容') #加密 osv=sha1.hexdigest() print(osv) bx=bytes(osv,encoding='utf-8') #转换类型 with open('1.txt','wb') as f: #以二进制写类型打开 f.write(bx) #写入文件 get_sha1('')
pycrypto模块:
from Crypto.Cipher import AES obj = AES.new('This is a key123', AES.MODE_CBC, 'This is an IV456') message = "The answer is no" ciphertext = obj.encrypt(message) >>> ciphertext '\xd6\x83\x8dd!VT\x92\xaa`A\x05\xe0\x9b\x8b\xf1' >>> obj2 = AES.new('This is a key123', AES.MODE_CBC, 'This is an IV456') >>> obj2.decrypt(ciphertext) 'The answer is no'