模块进阶

Python有一套很有用的标准库(standard library)。标准库会随着Python解释器,一起安装在你的电脑中的。 它是Python的一个组成部分。这些标准库是Python为你准备好的利器,可以让编程事半功倍。

用标准库
Python模块进阶、标准库、扩展库 Python 第1张

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

hashlib

import hashlib
m = hashlib.md5()   #创建hash对象,md5:(message-Digest Algorithm 5)消息摘要算法,得出一个128位的密文
print m             #<md5 HASH object>
m.update('itcast')  #更新哈希对象以字符串参数
print m.hexdigest() #返回十六进制数字字符串

应用实例
用于注册、登录....

import hashlib
import datetime
KEY_VALUE = 'Itcast'
now = datetime.datetime.now()
m = hashlib.md5()
str = '%s%s' % (KEY_VALUE,now.strftime("%Y%m%d"))
m.update(str.encode('utf-8'))
value = m.hexdigest()
print(value)

运行结果:

8ad2d682e3529dac50e586fee8dc05c0

更多标准库

http://python.usyiyi.cn/translate/python_352/library/index.html

常用扩展库

Python模块进阶、标准库、扩展库 Python 第2张
就可以运行起来静态服务。平时用它预览和下载文件太方便了。

在终端中输入命令:

python2中
  

python -m SimpleHTTPServer PORT

python3中

 python -m http.server PORT

Python模块进阶、标准库、扩展库 Python 第3张
Python模块进阶、标准库、扩展库 Python 第4张
读写excel文件
1.安装个easy_install工具

  sudo apt-get install python-setuptools

2.安装模块

sudo easy_install xlrd
sudo easy_install xlwt

matplotlib
Python模块进阶、标准库、扩展库 Python 第5张

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄