from enum import Enum from typing import Optional class RoleEnum(str, Enum): super = 'super' admin = 'admin' user = 'user' def greet(name: Optional[list[RoleEnum]] | str = None): if name is Non
string: 提供了字符集:ascii_lowercase, ascii_uppercase re: 正则表达式支持(pattern, string):match, search, findall, sub, split, finditer difflib: 序列的差异化比较: context_diff(s1, s2) 数据结构datetime: 处理日期,可用arrow代替 calendar: 日历: Calendar collections: 其他数据结构: deque, Counter, ...
这个库包含了多个内置模块 (以 C 编写),Python 程序员必须依靠它们来实现系统级功能,例如:文件 I/O等。 此外,还有大量以 Python 编写的模块,提供了日常编程中许多问题的标准解决方案。 其中,有些模块经过专门设计,通过将特定平台功能抽象化为平台中立的API来鼓励和加强Python程序的可移植性。它实际上也向Python程序...
不受运行环境Python版本的限制- 避免模块导入带来的开销from enum import Enum from typing import Optiona...
from dataclasses import dataclass, field from typing import Optional from enum import Enum, auto from datetime import date class ResourceType(Enum): # ① BOOK = auto() EBOOK = auto() VIDEO = auto() @dataclass class Resource: """Media resource description.""" identifier: str # ② title...
getLogger(__name__) class RequirementType(StrEnum): INSTALL = "install" TOP_LEVEL = "toplevel" BUILD = "build" BUILD_SYSTEM = "build-system" BUILD_BACKEND = "build-backend" BUILD_SDIST = "build-sdist" def parse_requirements_file( req_file: pathlib.Path, ) -> typing.Iterable[str]:...
6.1. string--通常字符操作 6.2. re--正则表达式操作 6.3. difflib--处理差异 6.4. textwrap--文本包含和填充 6.5. unicodedata--统一编码数据 6.6. stringprep--网络字符处理 6.7. readline--标准readline接口 6.8. rlcompleter--左右完成函数 7.二进制数据处理 ...
_dummy_thread _markupbase _osx_support _py_abc _pyio _sitebuiltins _strptime _threading_local _weakrefset abc argparse bisect calendar codecs collections collections.abc configparser contextlib copy copyreg dataclasses datetime dis dummy_threading ...
typing.NamedTuple 一种需要在字段上添加类型提示的替代方法——自 Python 3.5 起,3.6 中添加了class语法。 @dataclasses.dataclass 一个类装饰器,允许比以前的替代方案更多的定制化,增加了许多选项和潜在的复杂性——自 Python 3.7 起。 在讨论完这些类构建器之后,我们将讨论为什么数据类也是一个代码异味的名称:一...
_sre email plistlib typing _ssl encodings poplib undo _stat ensurepip posixpath unicodedata _string enum pprint unittest _strptime errno profile urllib _struct faulthandler pstats uu _symtable filecmp pty uuid _testbuffer fileinput py_compile venv ...