词表 · 第 7 篇
Python
1. approximate
- 译:近似的;大约的 | Python:描述浮点表示的精度(如
math.isclose的近似比较) - 例
math.isclosechecks approximate equality. —math.isclose检查近似相等。- Floats store an approximate value. — 浮点数存储的是近似值。
- 地道:approximately equal(近似相等)
- 短语:approximate value · approximate match · approximate equality
2. backport
- 译:向后移植 | Python:把新版本特性或修复移植到旧版本(如
backports系列库) - 例
- Backport the fix to Python 3.9. — 把修复 backport 到 Python 3.9。
- Use a backport library on older Python. — 在旧版 Python 上用 backport 库。
- 地道:backport a feature(向后移植某特性)
- 短语:backport to · backport library · backport fixes
3. circumstance
- 译:情况;环境 | Python:错误处理或文档中描述”在某种情况下”
- 例
- Under normal circumstances, the call succeeds. — 正常情况下调用会成功。
- In some circumstances, the GC may delay. — 某些情况下 GC 可能延迟。
- 地道:under no circumstances(决不)
- 短语:under the circumstances · in some circumstances · mitigating circumstances
4. coercion
- 译:强制类型转换 | Python:隐式类型转换(PEP 3141 数值塔;Py2 的
coerce已移除) - 短语:type coercion · implicit coercion · numeric coercion
5. compound
- 译:复合的 | Python:复合语句(compound statement,如
if/for/try/with等含子句块) - 例
ifis a compound statement. —if是复合语句。- Compound expressions can be nested. — 复合表达式可以嵌套。
- 地道:compound statement(复合语句)
- 短语:compound statement · compound expression · compound assignment
6. contiguous
- 译:连续的;邻接的 | Python:buffer protocol 中描述内存布局(C-/F-contiguous)
- 例
- The buffer is C-contiguous. — 该缓冲区是 C 连续的。
- NumPy arrays store data contiguously. — NumPy 数组连续存储数据。
- 地道:contiguous memory(连续内存)
- 短语:C-contiguous · Fortran-contiguous · contiguous block
7. decoupling
- 译:解耦 | Python:通过依赖注入、抽象基类等降低模块间耦合
- 例
- Decoupling makes code easier to test. — 解耦让代码更易测试。
- Use ABCs for decoupling. — 用抽象基类来解耦。
- 地道:loose coupling(松耦合)
- 短语:decouple modules · tight/loose coupling · decoupling layer
8. deliberately
- 译:故意地;审慎地 | Python:强调某设计是”刻意为之”
- 例
- We deliberately broke compatibility. — 我们故意破坏了兼容性。
- This was a deliberately chosen trade-off. — 这是有意权衡的结果。
- 地道:deliberate choice(有意为之的选择)
- 短语:deliberately raise · deliberately break · deliberate design
9. dispatch
- 译:分派;调度 | Python:依参数类型选择具体实现(
functools.singledispatch,PEP 443) - 短语:single dispatch · multiple dispatch · dispatch on type
10. generic function
- 译:泛型函数 | Python:依参数类型分派的函数(PEP 443
functools.singledispatch) - 例
singledispatchcreates a generic function. —singledispatch创建泛型函数。- A generic function dispatches by argument type. — 泛型函数按参数类型分派。
- 地道:single-dispatch generic function(单分派泛型函数)
- 短语:generic function · single dispatch · register an overload
11. granularity
- 译:粒度 | Python:日志、锁、缓存的粗细程度(fine-grained vs coarse-grained)
- 短语:fine-grained · coarse-grained · lock granularity
12. gratuitously
- 译:无端地;不必要地 | Python:批评代码”毫无理由地”破坏兼容性或加复杂度
- 例
- The library gratuitously breaks API. — 该库无端破坏 API。
- Don’t gratuitously nest functions. — 不要无故嵌套函数。
- 地道:gratuitous complexity(无谓的复杂性)
- 短语:gratuitously break · gratuitous complexity · gratuitous nesting
13. heterogeneous
- 译:异构的;成分各异的 | Python:元素类型不同的容器(heterogeneous list)
- 例
- Python lists are heterogeneous. — Python 列表是异构的。
- Heterogeneous data needs careful typing. — 异构数据需要小心处理类型。
- 地道:heterogeneous collection(异构集合)
- 短语:heterogeneous list · heterogeneous data · heterogeneous system
14. hierarchies
- 译:层次结构(复数) | Python:类继承层级、异常层级(exception hierarchy)
- 例
- Build shallow class hierarchies. — 建立浅层的类层次结构。
- The exception hierarchy is rooted at
BaseException. — 异常层次以BaseException为根。
- 地道:class hierarchy(类层级)
- 短语:class hierarchy · exception hierarchy · type hierarchy
15. homogeneous
- 译:同构的;同质的 | Python:元素类型相同(NumPy 的 homogeneous array)
- 例
- NumPy arrays are homogeneous. — NumPy 数组是同构的。
- Homogeneous data is faster to process. — 同质数据处理更快。
- 地道:homogeneous array(同构数组)
- 短语:homogeneous array · homogeneous data · homogeneous list
16. inheritance
- 译:继承 | Python:子类复用父类实现(single/multiple inheritance,MRO 决定查找顺序)
- 短语:multiple inheritance · MRO · single inheritance
17. introspection
- 译:内省;自省 | Python:运行时查看对象类型与属性(
type/dir/hasattr/inspect) - 例
- Use
dir()for introspection. — 用dir()进行内省。 - Introspection enables generic frameworks. — 内省让通用框架成为可能。
- Use
- 地道:runtime introspection(运行时内省)
- 短语:object introspection · introspect a module · self-introspection
18. provisional
- 译:临时的;暂行的 | Python:标准库中标记 API 可能变更(provisional API,PEP 411)
- 例
- The module is provisional in 3.x. — 该模块在 3.x 中是 provisional 的。
- Provisional APIs may change without notice. — provisional API 可能随时变更。
- 地道:provisional API(暂行 API)
- 短语:provisional API · provisional status · provisional module
19. robust
- 译:健壮的 | Python:对异常输入不崩溃(robust code, robust error handling)
- 短语:robust code · robust error handling · robust against
20. short-circuit
- 译:短路(电路/逻辑) | Python:
and/or布尔运算的短路求值 - 例
andshort-circuits on falsy values. —and遇到假值即短路。- Short-circuit evaluation avoids extra work. — 短路求值避免了额外开销。
- 地道:short-circuit evaluation(短路求值)
- 短语:short-circuit evaluation · short-circuit operator · logical short-circuit
21. wildcard
- 译:通配符 | Python:
from m import *中的*、fnmatch/glob模式匹配 - 例
*is an import wildcard. —*是 import 通配符。- Use wildcards carefully in
glob. — 在glob中谨慎使用通配符。
- 地道:wildcard import(通配导入)
- 短语:wildcard import · wildcard match · wildcard character
22. open-circuit
- 译:开路;断路 | Python:与 short-circuit 对应,多见于科学计算/电路建模场景
- 例
- An open-circuit has zero current. — 开路电流为零。
- Model the open-circuit voltage. — 建模开路电压。
- 地道:open-circuit voltage(开路电压)
- 短语:open-circuit voltage · open-circuit fault · open vs short circuit
23. contingency
- 译:意外事件;预案 | Python:异常处理与降级方案的设计
- 例
- Plan a contingency for network errors. — 为网络错误准备预案。
- The fallback is our contingency. — 回退机制就是我们的预案。
- 地道:contingency plan(应急预案)
- 短语:contingency plan · for any contingency · contingency handling
24. feedback
- 译:反馈(用户反馈;控制系统的反馈回路)
- 短语:user feedback · feedback loop · collect feedback
25. sinusoidal
- 译:正弦的;正弦波的 | Python:NumPy/SciPy 中生成正弦信号(
np.sin、sinusoidal wave) - 例
- Generate a sinusoidal signal with NumPy. — 用 NumPy 生成正弦信号。
- The plot shows a sinusoidal wave. — 图像呈正弦波形。
- 地道:sinusoidal waveform(正弦波形)
- 短语:sinusoidal wave · sinusoidal signal · sinusoidal oscillation
26. async
- 译:异步 | Python:
async def/async with/async for与 asyncio 相关关键字 - 例
- Define an async function with
async def. — 用async def定义异步函数。 - Run the coroutine with
asyncio. — 用asyncio运行协程。
- Define an async function with
- 地道:async I/O(异步 I/O)
- 短语:async def · async with · async/await
27. await
- 译:等待 | Python:
await挂起协程直到 awaitable 完成 - 例
awaitsuspends the coroutine. —await挂起协程。- Await the future to get the result. — 等待 future 取得结果。
- 地道:await a coroutine(等待一个协程)
- 短语:await expression · awaitable · await coroutine
28. bytecode
- 译:字节码 | Python:CPython 编译源码后由虚拟机执行的中间码(缓存在
.pyc) - 例
- Python compiles source to bytecode. — Python 把源码编译成字节码。
- Bytecode is cached in
.pycfiles. — 字节码缓存在.pyc文件中。
- 地道:compile to bytecode(编译为字节码)
- 短语:Python bytecode · .pyc cache · bytecode compiler
29. comprehension
- 译:推导式 | Python:紧凑构造序列的语法(list/dict/set/generator comprehension)
- 例
- List comprehensions are Pythonic. — 列表推导式很 Pythonic。
- Use a dict comprehension to build the mapping. — 用字典推导式构造映射。
- 地道:list comprehension(列表推导式)
- 短语:list comprehension · dict comprehension · set comprehension
30. coroutine
- 译:协程 | Python:可挂起与恢复的函数(
async def函数的调用结果) - 例
- A coroutine runs on an event loop. — 协程在事件循环上运行。
- Await a coroutine to complete. — 等待协程完成。
- 地道:drive a coroutine(驱动协程)
- 短语:async coroutine · coroutine function · awaitable coroutine
31. dataclass
- 译:数据类 | Python:PEP 557
@dataclass自动生成__init__/__repr__/__eq__等方法 - 例
@dataclasswrites boilerplate for you. —@dataclass帮你写样板代码。- Use
frozen=Truefor immutable dataclasses. — 用frozen=True得到不可变 dataclass。
- 地道:dataclass decorator(dataclass 装饰器)
- 短语:@dataclass · frozen dataclass · dataclass field
32. decorator
- 译:装饰器 | Python:以
@语法包装函数/类的可调用对象 - 例
- Apply a decorator with
@. — 用@应用装饰器。 - A decorator returns a new callable. — 装饰器返回新的可调用对象。
- Apply a decorator with
- 地道:stack decorators(叠用装饰器)
- 短语:function decorator · class decorator · decorator factory
33. duck typing
- 译:鸭子类型 | Python:不关心类型本身、只关心是否有需要的方法(“若它走起来像鸭子…”)
- 例
- Python relies on duck typing. — Python 依赖鸭子类型。
- Duck typing favors protocols over types. — 鸭子类型偏好协议而非具体类型。
- 地道:if it quacks like a duck(如果它叫起来像鸭子)
- 短语:duck typing · protocol-based · structural typing
34. generator
- 译:生成器 | Python:含
yield的函数,惰性产出值 - 例
- A generator yields values lazily. — 生成器惰性产出值。
- Use a generator to stream data. — 用生成器流式处理数据。
- 地道:generator expression(生成器表达式)
- 短语:generator function · yield · generator expression
35. GIL
英 /ˌdʒiː aɪ ˈel/ (Global Interpreter Lock) · 美 /ˌdʒiː aɪ ˈel/ · 🔊 英 美
- 译:GIL;全局解释器锁 | Python:CPython 中保证同一时刻仅一个线程执行字节码的互斥锁(PEP 703 计划移除)
- 例
- The GIL prevents true thread parallelism. — GIL 阻止真正的线程并行。
- Free-threaded Python removes the GIL. — free-threaded Python 移除 GIL。
- 地道:under the GIL(在 GIL 约束下)
- 短语:the GIL · hold the GIL · free-threaded / no-GIL
36. import
- 译:导入(导入模块或符号)
- 短语:import module · from … import · circular import
37. iterator
- 译:迭代器 | Python:实现
__next__与__iter__的对象,可被for消费 - 例
- An iterator produces values one at a time. — 迭代器一次产出一个值。
- Exhausted iterators raise
StopIteration. — 耗尽的迭代器会抛StopIteration。
- 地道:lazy iterator(惰性迭代器)
- 短语:iterator protocol · iter() / next() · infinite iterator
38. lambda
- 译:lambda 表达式 | Python:
lambda关键字定义的匿名函数(仅单表达式) - 例
- Sort with a
lambdakey. — 用lambda作为排序 key。 - A lambda cannot contain statements. — lambda 不能包含语句。
- Sort with a
- 地道:lambda expression(lambda 表达式)
- 短语:lambda expression · key=lambda · anonymous function
39. mypy
- 译:mypy | Python:流行的静态类型检查器(基于 PEP 484 类型注解)
- 例
- Run mypy before merging. — 合并前运行 mypy。
- Mypy catches type errors statically. — mypy 在静态阶段捕获类型错误。
- 地道:mypy strict mode(mypy 严格模式)
- 短语:mypy check · mypy config · mypy stubs
40. pip
- 译:pip | Python:官方包管理工具(preferred installer program)
- 例
- Install packages with
pip install. — 用pip install安装包。 - Pin versions in
requirements.txt. — 在requirements.txt中固定版本。
- Install packages with
- 地道:pip freeze(导出当前已装的版本)
- 短语:pip install · pip freeze · pip uninstall
41. pytest
- 译:pytest | Python:基于
assert与 fixture 的测试框架 - 例
- Write tests as plain functions in pytest. — 在 pytest 中用普通函数写测试。
- Fixtures handle setup and teardown. — fixture 负责建立与清理。
- 地道:pytest fixtures(pytest fixture)
- 短语:pytest fixture · parametrize · conftest.py
42. type hint
- 译:类型注解 | Python:PEP 484 引入的类型提示语法(运行时不强制检查)
- 例
- Add type hints to public APIs. — 给公开 API 加类型注解。
- Tools like mypy read type hints. — mypy 这类工具读取类型注解。
- 地道:gradual typing(渐进式类型系统)
- 短语:type hint · type annotation · typing module
43. virtualenv
- 译:virtualenv | Python:创建隔离 Python 环境的第三方工具(标准库对应
venv) - 例
- Create a virtualenv before installing deps. — 安装依赖前先创建 virtualenv。
- Activate the virtualenv first. — 先激活 virtualenv。
- 地道:virtualenv vs venv(virtualenv 与 venv 之别)
- 短语:virtualenvwrapper · activate virtualenv · venv module