Python基础之开发必备-标准库(内置模块)代码案例汇总详细介绍(持续更新……)

130 阅读26分钟

Python3标准库是Python编程语言的一部分,包含了大量的模块和函数,用于实现各种常见的编程任务。Python3标准库是Python编程中不可或缺的一部分,它提供了丰富的功能和工具,使得Python编程更加方便和高效。在本文中,我们将详细介绍Python3标准库的各个模块和函数。

原文:Python基础之开发必备-标准库(内置模块)代码案例汇总详细介绍(持续更新……)

图片.png

查看标准库

以下是几个查看Python3标准库(依赖库)的方法:

 

1、命令行模式下使用pydoc命令查看库

 

pydoc modules

图片.png  

2、在python编辑器中使用help()函数查看库

图片.png  

3、python编辑器中导入sys模块查看库

 

import sys

print(sys.modules.keys())

 

4、在命令行模式下使用pip指令查看库(大多为第三方安装的依赖库)

图片.png    

 

5、通过官网查看所有内置标准库:Python 模块索引 — Python 3.11.3 文档

 后面将分别详细介绍这些标准库的使用、应用场景和案例,敬请关注公众号:CTO Plus后续的发文。

标准库清单

python具有庞大的用户群,因其语法简洁,开发效率高而备受欢迎,同样,它的标准库与第三方库的支持也比较完善。python的标准库有上百个,以下即为Python3.11的标准库清单,按照字母顺序排序如下:

 

a

abc模块:Abstract base classes according to :pep:3119.

aifc模块:已移除: Read and write audio files in AIFF or AIFC format.

argparse模块:Command-line option and argument parsing library.

array模块:Space efficient arrays of uniformly typed numeric values.

ast模块:Abstract Syntax Tree classes and manipulation.

asynchat模块:已移除: Support for asynchronous command/response protocols.

asyncio模块:Asynchronous I/O.

asyncore模块:已移除: A base class for developing asynchronous socket handling services.

atexit模块:Register and execute cleanup functions.

audioop模块:已移除: Manipulate raw audio data.

 

b

base64模块:RFC 4648: Base16, Base32, Base64 Data Encodings; Base85 and Ascii85

bdb模块:Debugger framework.

binascii模块:Tools for converting between binary and various ASCII-encoded binary representations.

bisect模块:Array bisection algorithms for binary searching.

builtins模块:The module that provides the built-in namespace.

bz2模块:Interfaces for bzip2 compression and decompression.

 

c

calendar模块:Functions for working with calendars, including some emulation of the Unix cal program.

cgi模块:已移除: Helpers for running Python scripts via the Common Gateway Interface.

cgitb模块:已移除: Configurable traceback handler for CGI scripts.

chunk模块:已移除: Module to read IFF chunks.

cmath模块:Mathematical functions for complex numbers.

cmd模块:Build line-oriented command interpreters.

code模块:Facilities to implement read-eval-print loops.

codecs模块:Encode and decode data and streams.

codeop模块:Compile (possibly incomplete) Python code.

collections模块:Container datatypes

colorsys模块:Conversion functions between RGB and other color systems.

compileall模块:Tools for byte-compiling all Python source files in a directory tree.

concurrent模块:

configparser模块:Configuration file parser.

contextlib模块:Utilities for with-statement contexts.

contextvars模块:Context Variables

copy模块:Shallow and deep copy operations.

copyreg模块:Register pickle support functions.

cProfile模块:

crypt (Unix)模块:已移除: The crypt() function used to check Unix passwords.

csv模块:Write and read tabular data to and from delimited files.

ctypes模块:A foreign function library for Python.

curses (Unix)模块:An interface to the curses library, providing portable terminal handling.

 

d

dataclasses模块:Generate special methods on user-defined classes.

datetime模块:Basic date and time types.

dbm模块:Interfaces to various Unix "database" formats.

decimal模块:Implementation of the General Decimal Arithmetic Specification.

difflib模块:Helpers for computing differences between objects.

dis模块:Disassembler for Python bytecode.

distutils模块:Support for building and installing Python modules into an existing Python installation.

doctest模块:Test pieces of code within docstrings.

 

e

email模块:Package supporting the parsing, manipulating, and generating email messages.

encodings模块:

ensurepip模块:Bootstrapping the "pip" installer into an existing Python installation or virtual environment.

enum模块:Implementation of an enumeration class.

errno模块:Standard errno system symbols.

 

f

faulthandler模块:Dump the Python traceback.

fcntl (Unix)模块:The fcntl() and ioctl() system calls.

filecmp模块:Compare files efficiently.

fileinput模块:Loop over standard input or a list of files.

fnmatch模块:Unix shell style filename pattern matching.

fractions模块:Rational numbers.

ftplib模块:FTP protocol client (requires sockets).

functools模块:Higher-order functions and operations on callable objects.

 

g

gc模块:Interface to the cycle-detecting garbage collector.

getopt模块:Portable parser for command line options; support both short and long option names.

getpass模块:Portable reading of passwords and retrieval of the userid.

gettext模块:Multilingual internationalization services.

glob模块:Unix shell style pathname pattern expansion.

graphlib模块:Functionality to operate with graph-like structures

grp (Unix)模块:The group database (getgrnam() and friends).

gzip模块:Interfaces for gzip compression and decompression using file objects.

 

h

hashlib模块:Secure hash and message digest algorithms.

heapq模块:Heap queue algorithm (a.k.a. priority queue).

hmac模块:Keyed-Hashing for Message Authentication (HMAC) implementation

html模块:Helpers for manipulating HTML.

http模块:HTTP status codes and messages

 

i

idlelib模块:Implementation package for the IDLE shell/editor.

imaplib模块:IMAP4 protocol client (requires sockets).

imghdr模块:已移除: Determine the type of image contained in a file or byte stream.

imp模块:已移除: Access the implementation of the import statement.

importlib模块:The implementation of the import machinery.

inspect模块:Extract information and source code from live objects.

io模块:Core tools for working with streams.

ipaddress模块:IPv4/IPv6 manipulation library.

itertools模块:Functions creating iterators for efficient looping.

 

j

json模块:Encode and decode the JSON format.

 

k

keyword模块:Test whether a string is a keyword in Python.

 

l

lib2to3模块:The 2to3 library

linecache模块:Provides random access to individual lines from text files.

locale模块:Internationalization services.

-模块:logging模块:Flexible event logging system for applications.

lzma模块:A Python wrapper for the liblzma compression library.

 

m

mailbox模块:Manipulate mailboxes in various formats

mailcap模块:已移除: Mailcap file handling.

marshal模块:Convert Python objects to streams of bytes and back (with different constraints).

math模块:Mathematical functions (sin() etc.).

mimetypes模块:Mapping of filename extensions to MIME types.

mmap模块:Interface to memory-mapped files for Unix and Windows.

modulefinder模块:Find modules used by a script.

msilib (Windows)模块:已移除: Creation of Microsoft Installer files, and CAB files.

msvcrt (Windows)模块:Miscellaneous useful routines from the MS VC++ runtime.

multiprocessing模块:Process-based parallelism.

 

n

netrc模块:Loading of .netrc files.

nis (Unix)模块:已移除: Interface to Sun's NIS (Yellow Pages) library.

nntplib模块:已移除: NNTP protocol client (requires sockets).

numbers模块:Numeric abstract base classes (Complex, Real, Integral, etc.).

 

o

operator模块:Functions corresponding to the standard operators.

optparse模块:已移除: Command-line option parsing library.

os模块:Miscellaneous operating system interfaces.

ossaudiodev (Linux, FreeBSD)模块:已移除: Access to OSS-compatible audio devices.

 

p

pathlib模块:Object-oriented filesystem paths

pdb模块:The Python debugger for interactive interpreters.

pickle模块:Convert Python objects to streams of bytes and back.

pickletools模块:Contains extensive comments about the pickle protocols and pickle-machine opcodes, as well as some useful functions.

pipes (Unix)模块:已移除: A Python interface to Unix shell pipelines.

pkgutil模块:Utilities for the import system.

platform模块:Retrieves as much platform identifying data as possible.

plistlib模块:Generate and parse Apple plist files.

poplib模块:POP3 protocol client (requires sockets).

posix (Unix)模块:The most common POSIX system calls (normally used via module os).

pprint模块:Data pretty printer.

profile模块:Python source profiler.

pstats模块:Statistics object for use with the profiler.

pty (Unix)模块:Pseudo-Terminal Handling for Unix.

pwd (Unix)模块:The password database (getpwnam() and friends).

py_compile模块:Generate byte-code files from Python source files.

pyclbr模块:Supports information extraction for a Python module browser.

pydoc模块:Documentation generator and online help system.

 

q

queue模块:A synchronized queue class.

quopri模块:Encode and decode files using the MIME quoted-printable encoding.

 

r

random模块:Generate pseudo-random numbers with various common distributions.

re模块:Regular expression operations.

readline (Unix)模块:GNU readline support for Python.

reprlib模块:Alternate repr() implementation with size limits.

resource (Unix)模块:An interface to provide resource usage information on the current process.

rlcompleter模块:Python identifier completion, suitable for the GNU readline library.

runpy模块:Locate and run Python modules without importing them first.

 

s

sched模块:General purpose event scheduler.

secrets模块:Generate secure random numbers for managing secrets.

select模块:Wait for I/O completion on multiple streams.

selectors模块:High-level I/O multiplexing.

shelve模块:Python object persistence.

shlex模块:Simple lexical analysis for Unix shell-like languages.

shutil模块:High-level file operations, including copying.

signal模块:Set handlers for asynchronous events.

site模块:Module responsible for site-specific configuration.

smtpd模块:已移除: A SMTP server implementation in Python.

smtplib模块:SMTP protocol client (requires sockets).

sndhdr模块:已移除: Determine type of a sound file.

socket模块:Low-level networking interface.

socketserver模块:A framework for network servers.

spwd (Unix)模块:已移除: The shadow password database (getspnam() and friends).

sqlite3模块:A DB-API 2.0 implementation using SQLite 3.x.

ssl模块:TLS/SSL wrapper for socket objects

stat模块:Utilities for interpreting the results of os.stat(), os.lstat() and os.fstat().

statistics模块:Mathematical statistics functions

string模块:Common string operations.

stringprep模块:String preparation, as per RFC 3453

struct模块:Interpret bytes as packed binary data.

subprocess模块:Subprocess management.

sunau模块:已移除: Provide an interface to the Sun AU sound format.

symtable模块:Interface to the compiler's internal symbol tables.

sys模块:Access system-specific parameters and functions.

sysconfig模块:Python's configuration information

syslog (Unix)模块:An interface to the Unix syslog library routines.

 

t

tabnanny模块:Tool for detecting white space related problems in Python source files in a directory tree.

tarfile模块:Read and write tar-format archive files.

telnetlib模块:已移除: Telnet client class.

tempfile模块:Generate temporary files and directories.

termios (Unix)模块:POSIX style tty control.

test模块:Regression tests package containing the testing suite for Python.

textwrap模块:Text wrapping and filling

threading模块:Thread-based parallelism.

time模块:Time access and conversions.

timeit模块:Measure the execution time of small code snippets.

tkinter模块:Interface to Tcl/Tk for graphical user interfaces

token模块:Constants representing terminal nodes of the parse tree.

tokenize模块:Lexical scanner for Python source code.

tomllib模块:Parse TOML files.

trace模块:Trace or track Python statement execution.

traceback模块:Print or retrieve a stack traceback.

tracemalloc模块:Trace memory allocations.

tty (Unix)模块:Utility functions that perform common terminal control operations.

turtle模块:An educational framework for simple graphics applications

turtledemo模块:A viewer for example turtle scripts

types模块:Names for built-in types.

typing模块:Support for type hints (see :pep:484).

 

u

unicodedata模块:Access the Unicode Database.

unittest模块:Unit testing framework for Python.

urllib模块:

uu模块:已移除: Encode and decode files in uuencode format.

uuid模块:UUID objects (universally unique identifiers) according to RFC 4122

 

v

venv模块:Creation of virtual environments.

 

w

warnings模块:Issue warning messages and control their disposition.

wave模块:Provide an interface to the WAV sound format.

weakref模块:Support for weak references and weak dictionaries.

webbrowser模块:Easy-to-use controller for web browsers.

winreg (Windows)模块:Routines and objects for manipulating the Windows registry.

winsound (Windows)模块:Access to the sound-playing machinery for Windows.

wsgiref模块:WSGI Utilities and Reference Implementation.

 

x

xdrlib模块:已移除: Encoders and decoders for the External Data Representation (XDR).

xml模块:Package containing XML processing modules

xmlrpc模块:

 

z

zipapp模块:Manage executable Python zip archives

zipfile模块:Read and write ZIP-format archive files.

zipimport模块:Support for importing Python modules from ZIP archives.

zlib模块:Low-level interface to compression and decompression routines compatible with gzip.

zoneinfo模块:IANA time zone support

 

我们可以根据需要选择合适的模块和函数,实现各种常见的编程任务。库的存放位置一般放于Python安装目录下的 lib/site-packages 目录中。

图片.png  

常用的标准库及代码示例

Python的标准库比较多,此处选一些日常开发中常用到的有用的标准库做简要介绍,后面文章中将分别逐一介绍标准库的特性、作用以及使用方法。

更多关于Python的相关技术点,敬请关注公众号:CTO Plus后续的发文,有问题欢迎后台留言交流。

1. abc模块

 

abc模块是Python中的抽象基类模块。使用Python抽象基类可以非常方便地定义抽象接口,抽象基类模块提供了一种方便的方式来定义这些接口,以及一些实现其它类的抽象基类。

 

2. argparse模块

 

argparse模块是Python中的命令行解析模块。它可以帮助程序处理命令行参数,包括选项、参数、子命令,以及默认值等内容。

 

3. array模块

 

array模块提供了一种便捷的方式来处理数值数据。它可以创建并操作固定类型的数组,例如整数、浮点数等。

 

4. asyncio模块

 

asyncio模块是Python中的异步编程模块。它是Python 3.4之后新增的一个标准库。通过使用协程和事件循环,asyncio模块可以轻松实现异步编程,提高程序效率。

 

5. base64模块

 

base64模块提供了一种基于编码表的数据编码方式。它可以将二进制数据编码为ASCII文本,也可以将ASCII文本解码为二进制数据。

 

6. binascii模块

 

binascii模块是Python中提供了很多用于二进制转换的函数。它可以实现二进制数据和ASCII文本的互相转换,如16进制、base64编码等。

 

7. builtins模块

 

builtins模块是Python中内置函数的名称空间。这些内置函数可以直接从名称空间中使用,无需导入任何模块。

 

8. bz2模块

 

bz2模块提供了一种压缩和解压缩数据的方式。它使用Burrows-Wheeler变换和霍夫曼编码来实现数据压缩。

 

9. calendar模块

 

calendar模块提供了一些用于处理日历和日期的函数。可以使用它来获取某个月份的日历,或者计算某个日期之间的差值等。

 

10. cmath模块

 

cmath模块提供了一些用于复数运算的函数。它包括常见的数学运算,如求模、求幂、求指数等。

 

11. collections模块

 

collections模块提供了一些扩展的容器类型。这些容器可以用于替代Python内置的容器类型,如list、dict等。其中最常用的是namedtuple、deque、Counter和OrderedDict。

 

12. configparser模块

 

configparser模块提供了一种处理配置文件的方式。可以使用它来读取和写入INI格式的配置文件。

 

13. contextlib模块

 

contextlib模块提供了一种方便的方式来管理上下文。它可以使用with语句来管理资源,如文件、网络连接等。

 

14. copy模块

 

copy模块提供了一种复制Python对象的方式。它可以实现浅复制和深复制两种方式,用于创建对象的副本。

 

15. csv模块

 

csv模块提供了一种处理CSV格式文件的方式。可以使用它来读取和写入CSV文件。

 

16. ctypes模块

 

ctypes模块提供了一种与C语言库交互的方式。它可以使用Python代码调用C语言库中的函数,或者将Python对象转换为C语言中的数据类型。

 

17. dataclasses模块

 

dataclasses模块在Python 3.7中引入,旨在简化声明数据类的方式。通过使用装饰器来自动推断数据类的属性和方法,使得代码更加清晰、易读和易扩展。

 

18. decimal模块

 

decimal模块提供了一种高精度的十进制计算方式。它可以避免由于浮点数精度问题而导致的计算错误。

 

19. difflib模块

 

difflib模块提供了一种比较文本文件的方式。可以使用它来比较两个文件之间的差异。


20. dis模块

 

dis模块提供了一种反汇编Python字节码的方式。可以使用它来查看Python代码的底层实现。

 

21. email模块

 

email模块提供了一种处理电子邮件的方式。可以使用它来创建、发送和接收电子邮件。

 

22. encodings模块

 

encodings模块提供了一种处理文本编码的方式。可以使用它来转换不同编码的文本。

 

23. enum模块

 

enum模块提供了一种定义枚举类型的方式。可以使用它来定义一组有限的值。

 

24. fileinput模块

 

fileinput模块提供了一种处理多个文件的方式。可以使用它来逐行读取多个文件,或者从标准输入读取数据。

 

25. fnmatch模块

 

fnmatch模块提供了一种用于文件名匹配的方式。可以使用它来匹配文件名中的通配符。

 

26. functools模块

 

functools模块提供了一些用于函数式编程的工具函数。其中最常用的是partial和reduce函数。

 

27. gc模块

 

gc模块提供了一种管理Python垃圾回收的方式。可以使用它来手动控制垃圾回收器的行为。

 

28. hashlib模块

 

hashlib模块提供了一种加密和散列算法的方式。可以使用它来实现MD5、SHA1等算法。

 

29. heapq模块

 

heapq模块提供了一种堆的实现方式。可以使用它来实现堆排序、优先队列等。

 

30. hmac模块

 

hmac模块提供了一种使用哈希函数的方式来保证数据完整性和安全性。可以使用它来实现消息认证码等。

 

31. html模块

 

html模块提供了一种处理HTML文本的方式。可以使用它来解析、生成和格式化HTML文本。

 

32. http模块

 

http模块提供了一种处理HTTP协议的方式。可以使用它来实现HTTP客户端和服务器。

 

33. imaplib模块

 

imaplib模块提供了一种处理IMAP协议的方式。可以使用它来实现IMAP客户端。

 

34. imghdr模块

 

imghdr模块提供了一种判断图像文件类型的方式。可以使用它来判断图像文件的格式,如JPEG、PNG等。

 

35. imp模块

 

imp模块提供了一种动态加载Python模块的方式。可以使用它来动态加载Python模块,以便在运行时扩展程序功能。

 

36. importlib模块

 

importlib模块提供了一种更加灵活和可扩展的模块加载方式。可以使用它来动态加载Python模块,或者自定义模块加载器。

 

37. inspect模块

 

inspect模块提供了一种获取对象信息的方式。可以使用它来获取函数、类、方法等对象的信息。

 

38. io模块

 

io模块提供了一种统一的I/O接口。可以使用它来操作文件、网络连接、内存等不同类型的数据源。

 

39. itertools模块

 

itertools模块提供了一些用于迭代器操作的工具函数。其中最常用的是chain、count、cycle、repeat和zip_longest等。

 

40. distutils模块

 

distutils模块是一个旧的包发布和安装工具,用于将Python代码转换成平台特定的二进制代码(如Windows的.exe文件)并将其打包为tarball或ZIP文件。尽管已经存在许多替代工具(如setuptools和pip),但distutils仍然是Python本身的一部分。

 

41. os模块

 

os模块提供了访问操作系统功能的接口,包括文件操作、进程管理、环境变量等。os模块中的函数可以让Python程序与操作系统进行交互,实现各种文件和目录操作。os模块包含普遍的操作系统功能,如文件操作、目录等,与具体的平台无关

代码实战示例参考:blog.csdn.net/zhouruifu20…

更多关于Python的相关技术点,敬请关注公众号:CTO Plus后续的发文,有问题欢迎后台留言交流。

42. sys模块

 

sys模块提供了访问Python解释器的功能,包括解释器的版本、路径、命令行参数等。sys模块中的函数可以让Python程序与解释器进行交互,实现各种系统级别的操作。sys模块提供了一系列有关Python运行环境的变量和函数

 

43. re模块

 

re模块提供了正则表达式的支持,可以用于字符串匹配和替换。re模块中的函数可以让Python程序进行高效的字符串处理,实现各种文本操作。

 

44. datetime模块

 

datetime模块提供了日期和时间的处理功能,可以用于日期和时间的计算、格式化、解析等。datetime模块中的函数可以让Python程序进行高效的日期和时间处理,实现各种时间操作。

datetime模块是对time模块的一个高级封装(time包基于C语言的库函数)

 

45. math模块

 

math模块提供了数学计算的支持,包括数学函数、常量、随机数等。math模块中的函数可以让Python程序进行高效的数学计算,实现各种数学操作。

 

46. random模块

 

random模块提供了随机数的支持,可以用于生成随机数、随机序列等。random模块中的函数可以让Python程序进行高效的随机数处理,实现各种随机操作。

Python中的random模块用于生成随机数。

 

47. pickle模块

 

pickle模块提供了序列化和反序列化的支持,可以将Python对象转换为二进制数据,或者将二进制数据转换为Python对象。pickle模块中的函数可以让Python程序进行高效的数据存储和传输,实现各种数据操作。序列化处理模块,常用dump()、load()方法。

 

48. json模块

 

json模块提供了JSON格式的支持,可以将Python对象转换为JSON格式的数据,或者将JSON格式的数据转换为Python对象。json模块中的函数可以让Python程序进行高效的数据存储和传输,实现各种数据操作。也可以用来对json文件的处理。

代码实战示例参考:blog.csdn.net/zhouruifu20…

 

49. urllib模块

 

urllib模块提供了HTTP请求的支持,可以用于发送HTTP请求、获取HTTP响应等。urllib模块中的函数可以让Python程序进行高效的网络操作,实现各种网络操作。

代码实战示例参考:blog.csdn.net/zhouruifu20…

 

50. socket模块

 

socket模块提供了网络通信的支持,可以用于创建网络连接、发送和接收数据等。socket模块中的函数可以让Python程序进行高效的网络通信,实现各种网络操作。

 

51. time模块

 

time模块是Python3标准库中的一个模块,用于时间的相关处理。time模块包含了很多与时间有关的函数和类,例如时间戳、时间格式化、延时等。通过time模块可以实现各种时间操作,包括日期时间转换、计时等等。

 

52. subprocess模块

 

subprocess模块是Python3标准库中的一个模块,子进程管理模块,常用call()、run()、Popen()等方法。可以使得Python程序调用其他程序或者系统命令。subprocess模块提供了一些函数使得Python程序可以很方便地执行其他程序和系统命令,并且可以实现与其他程序的交互。官方文档

 

53. shutil模块

 

shutil模块是Python3标准库中的一个模块,提供了一系列高级的文件操作函数。shutil模块可以用于复制文件、移动文件、删除文件等等。此外,shutil模块还提供了一些对压缩文件和文件夹的操作函数。对文件(夹)、压缩包进行处理的模块(移动/复制/打包/解压/修改权限)。

 

54. hashlib/hmac/uuid模块

 

hashlib模块提供了密码学哈希函数,hmac模块提供了HMAC(密钥相关哈希)函数,uuid模块提供了生成唯一ID的工具函数。这些模块可以用于加密、校验数据的完整性等操作。消息摘要/加密/全局唯一标识符

 

55. configparser模块

 

configparser模块是Python3标准库中的一个模块,用于读取和解析配置文件。configparser模块可以读取INI配置文件,并将其解析成字典形式,用于方便地读取配置信息。ini配置文件解析模块。

详细使用示例参考:blog.csdn.net/zhouruifu20…

 

56. itertools模块

 

itertools模块是Python3标准库中的一个模块,一个创建快速、高效迭代器的模块,提供了各种迭代器函数,用于对迭代器对象进行操作。itertools模块可以用于生成笛卡尔积、组合、排列等操作,方便快捷地进行迭代操作。官方文档

更多关于Python的相关技术点,敬请关注公众号:CTO Plus后续的发文,有问题欢迎后台留言交流。

57. logging模块

 

logging模块是Python3标准库中的一个模块,用于实现灵活的日志记录功能。logging模块可以对程序进行日志记录,可以控制日志记录的格式、级别和输出目标等参数。

 

58. optparse模块

 

optparse模块是Python3标准库中的一个模块,用于解析命令行参数。optparse模块可以解析命令行的参数,并将其转换为Python程序可以理解的数据结构,方便程序进行后续操作。命令行解析模块。

 

59. docopt模块

 

docopt模块是Python的第三方模块,可以根据docstring自动生成命令行参数解析器。docopt模块可以读取docstring中的文本,并据此自动生成命令行参数解析器,简化程序的命令行参数解析操作。

 

60. csv模块

 

csv模块是Python3标准库中的一个模块,用于读写CSV文件。csv模块提供了读取和写入CSV文件的接口,可以方便地进行CSV文件的操作。

 

61. xml.etree.ElementTree模块

 

xml.etree.ElementTree模块是Python3标准库中的一个模块,用于对XML文本进行解析和构建DOM树。xml.etree.ElementTree模块提供了很多函数,可以帮助程序对XML文本进行解析、构建DOM树等操作。

 

62. tempfile模块

 

tempfile模块是Python3标准库中的一个模块,用于创建临时文件和目录。tempfile模块提供了一些函数,可以帮助程序快速创建临时文件和目录,用于实现各种文件和目录操作。

 

63. timeit模块

 

timeit模块是Python3标准库中的一个模块,用于测试代码的执行时间。timeit模块提供了计时器函数,可以测量代码执行时间,并提供了一些控制函数,用于精确控制计时器的行为。官方文档

 

64. gzip模块

 

gzip模块提供了一种压缩和解压缩数据的方式。可以使用它来减小数据的大小,节省存储和传输空间。gzip模块支持文件的压缩和解压缩操作。

代码实战示例参考:blog.csdn.net/zhouruifu20…

 

65. zipfile模块

 

zipfile模块提供了一种处理ZIP文件的方式。可以使用它来读取、写入、提取文件和写入文件到ZIP文件中。zipfile模块在处理压缩文件时非常方便。

代码实战示例参考:blog.csdn.net/zhouruifu20…

 

66. copy模块

 

copy模块提供了一种复制数据的方式。可以使用它来复制对象、文件和目录。copy模块提供了一系列copy()函数,可根据需要进行数据复制。

代码实战示例参考:blog.csdn.net/zhouruifu20…

 

67. types模块

 

types模块提供了一种动态创建自定义类型的方式。可以使用它来创建新的类型,或动态扩展已有的类型。types模块还可以用于Python解释器的内部处理。

代码实战示例参考:blog.csdn.net/zhouruifu20…

 

68. winreg(Windows)模块

 

winreg模块提供了一种处理Windows注册表的方式。可以使用它来读取、写入和删除注册表项和值。winreg模块提供的功能类似于Windows系统自带的注册表编辑器。

代码实战示例参考:blog.csdn.net/zhouruifu20…

 

70. warnings模块

 

warnings模块提供了一种处理警告信息的方式。可以使用它来控制警告信息的输出和处理,避免影响程序的正常运行。与Python 3中的warnings模块一样,也可使用filterwarnings()函数来定制警告过滤器。

 

71. wave模块

 

wave模块提供了一种处理WAV音频文件的方式。可以使用它来读取、写入和处理音频数据。wave模块允许用户读取和写入通用的WAV文件格式,其中包含音频数据的样本值,但不包括压缩格式的音频文件。

 

72. weakref模块

 

weakref模块提供了一种实现弱引用的方式。可以使用它来避免循环引用和内存泄漏。Python中,垃圾回收机制负责删除对象,但是对于循环引用的对象,垃圾回收机制不起作用。weakref可以创建一种不会增加对象计数器的对象引用,即弱引用,当弱引用所指向的对象被删除时,弱引用自身变为None。

更多关于Python的相关技术点,敬请关注公众号:CTO Plus后续的发文,有问题欢迎后台留言交流。

73. webbrowser模块

 

webbrowser模块提供了一种打开Web浏览器并显示Web资源的方式。可以使用它来访问指定URL,或打开默认的浏览器,并执行基本的浏览器操作,如前进、后退、刷新等。

 

74. wsgiref模块

 

wsgiref模块提供了一个符合WSGI规范的Web服务器(wsgiref.simple_server)和一个符合WSGI规范的Web应用程序框架(wsgiref.handlers.CGIHandler)。即可以使用wsgiref实现自己的Web应用程序,同时也可以使用它来测试和调试基于WSGI的Web应用程序。

 

75. xml模块

 

xml模块提供了一种解析和生成XML文档的方式。可以使用它来读取和写入XML文档,同时提供了一些内置的方法来处理XML文档,如DOM(文档对象模型)、SAX(简单API for XML)和ElementTree等。

 

76. xmlrpc模块

 

xmlrpc模块提供了一种使用XML-RPC协议的方式。可以使用它来实现分布式系统中的远程过程调用(RPC)功能,允许客户端和服务器之间互相调用函数。

 

77. zipapp模块

 

zipapp模块提供了一种将Python应用程序打包成zip文件的方式。可以使用它来将Python应用程序和依赖的模块打包成单个zip文件,从而方便分发和部署。

 

78. zipimport模块

 

zipimport模块提供了一种从zip文件中导入模块的方式。可以使用它来将模块的代码和数据打包成zip文件(或其他压缩文件),并使用import语句进行加载。该模块使用Python的import机制,允许将整个Python应用程序打包成一个zip文件。

 

79. zlib模块

zlib模块提供了一种压缩和解压缩数据的方式。可以使用它来减小数据的大小,节省存储和传输空间。zlib是一个流压缩库,用来对数据进行压缩和解压缩,支持多种压缩算法和压缩级别。

更多关于Python的相关技术点,敬请关注公众号:CTO Plus后续的发文,有问题欢迎后台留言交流。

标准库系列-推荐阅读:

推荐阅读: