Python Basic Standard Library and Common Third Party Library Case Tutorial

  • 2021-11-14 06:37:00
  • OfStack

Python Fundamentals: Standard and Common Third Party Libraries

The standard libraries for Python are:

名称 作用
datetime 为日期和时间处理同时提供了简单和复杂的方法。
zlib 直接支持通用的数据打包和压缩格式:zlib,gzip,bz2,zipfile,以及 tarfile。
random 提供了生成随机数的工具。
math 为浮点运算提供了对底层C函数库的访问。
sys 工具脚本经常调用命令行参数。这些命令行参数以链表形式存储于 sys 模块的 argv 变量。
glob 提供了1个函数用于从目录通配符搜索中生成文件列表。
os 提供了不少与操作系统相关联的函数。

The third-party libraries commonly used by Python are:

名称 作用 使用参考
Scrapy 爬虫工具常用的库。 https://www.ofstack.com/article/217779.htm
Requests http库。
Pillow 是PIL(Python图形库)的1个分支。适用于在图形领域工作的人。 https://www.ofstack.com/article/217786.htm
matplotlib 绘制数据图的库。对于数据科学家或分析师非常有用。
OpenCV 图片识别常用的库,通常在练习人脸识别时会用到 https://www.ofstack.com/article/217790.htm
pytesseract 图片文字识别,即OCR识别 https://www.ofstack.com/article/217792.htm
wxPython Python的1个GUI(图形用户界面)工具。
Twisted 对于网络应用开发者最重要的工具。
SymPy SymPy可以做代数评测、差异化、扩展、复数等等。
SQLAlchemy 数据库的库。
SciPy Python的算法和数学工具库。
Scapy 数据包探测和分析库。
pywin32 提供和windows交互的方法和类的Python库。
pyQT Python的GUI工具。给Python脚本开发用户界面时次于wxPython的选择。
pyGtk 也是Python GUI库。
Pyglet 3D动画和游戏开发引擎。
Pygame 开发2D游戏的时候使用会有很好的效果。
NumPy 为Python提供了很多高级的数学方法。
nose Python的测试框架。
nltk 自然语言工具包。
IPython Python的提示信息。包括完成信息、历史信息、shell功能,以及其他很多很多方面。
BeautifulSoup xml和html的解析库,对于新手非常有用。

Reference example of standard library usage:

datetime Library:

Provides methods for both date and time processing.


from datetime import date
# Import Time Library 
now=date.today()
# Take the current time 
print(now)
birthday=date(1987,12,3)
print(birthday)
age=now-birthday
# Hypothetical age = Current date - Date of Birthday 
print(age)

The running result is:

2019-05-04
1987-12-03
11475 days, 0:00:00

zlib Library:

Provides compression and decompression functions.


import zlib
m = b'This is a test compress'
print(m)
m1=len(m)
# View the length of a string 
print(m1)
t = zlib.compress(m)
# Assume that the compressed content is t
t1=len(t)
# View the compressed content t The length of 
print(t)
print(t1)
s = zlib.decompress(t)
# The extracted content is s
print(s)

The running result is:

b'This is a test compress'
23
b'x\x9c\x0b\xc9\xc8,V\x00\xa2D\x85\x92\xd4\xe2\x12\x85\xe4\xfc\xdc\x82\xa2\xd4\xe2b\x00ah\x08\x82'
29
b'This is a test compress'

sys Library:

Invoke command line arguments, often using sys. path, to view python and the dependent library package installation path of the system.


import sys
a=sys.path
# Assume that the system path is a
print(a)

The running result is:

['/Users/alice/PycharmProjects/untitled', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/nose-1.3.7-py2.7.egg', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/tornado-5.0.2-py2.7-macosx-10.13-intel.egg', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/backports_abc-0.5-py2.7.egg', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/singledispatch-3.4.0.3-py2.7.egg', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/futures-3.2.0-py2.7.egg', '/Users/alice/PycharmProjects/untitled', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python37.zip', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload', '/Users/alice/venv/untitled/lib/python3.7/site-packages', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC']


Related articles: