python-术语表

Glossary

术语表

BDFL

Benevolent Dictator For Life被指python的作者,直译过来为”终身的慈善独裁者“,大概是指作者一生都会免费慈善关注python,并在必要的时刻做出独裁决定。

Benevolent 英 [bəˈnevələnt]
adj. 好心肠的;与人为善的;乐善好施的;慈善的

dictator英 [ˈdɪkˌteɪtə,dɪkˈteɪ-]
n. 独裁者;专制者;发号施令者;专横的人

bytes-like object 
An object that supports the Buffer Protocol, like bytes, bytearray or memoryview. Bytes-like objects can be used for various operations that expect binary data, such as compression, saving to a binary file or sending over a socket. Some operations need the binary data to be mutable, in which case not all bytes-like objects can apply.

coercion
英 [kəʊ'ɜ:ʃn] n. 强迫;高压政治;强制

强制类型转换,例:int(3.15)

EAFP 
Easier to ask for forgiveness than permission. 这个是指python的一种编码规则,不管一个数据是否合法,一般先用try去执行,当except时再做处理。与之相对的是下面的LBYL。

LBYL 
Look before you leap. 这个是与python相对的一种规则,在C语言中都是先去if判断,满足条件才会执行。相对于EAFP有一个缺点就是,当多线程时if判断条件满足后,但是其他线程修改了后依然不会满足,所以在python中EAFP相对会好一些。

parameters & arguments

parameter是在函数定义时的参数,argument是在函数调用时实际传入的参数。参见手册FAQ What is the difference between arguments and parameters?

regular package & namespace package
Regular package:A traditional package, such as a directory containing an __init__.py file.

Namespace package:A PEP 420 package which serves only as a container for subpackages. Namespace packages may have no physical representation, and specifically are not like a regular package because they have no __init__.py file.

new-style class

新型类:在python3种已经不存在经典类了,都属于新型类。python2种定义的时候从object继承的类为新型类,不是从object继承的为经典类。

context manager 
An object which controls the environment seen in a with statement by defining __enter__() and __exit__() methods. See PEP 343. 
descriptor 
Any object which defines the methods __get__(), __set__(), or __delete__(). When a class attribute is a descriptor, its special binding behavior is triggered upon attribute lookup. Normally, using a.b to get, set or delete an attribute looks up the object named b in the class dictionary for a, but if b is a descriptor, the respective descriptor method gets called. Understanding descriptors is a key to a deep understanding of Python because they are the basis for many features including functions, methods, properties, class methods, static methods, and reference to super classes.

duck-typing 
A programming style which does not look at an object’s type to determine if it has the right interface; instead, the method or attribute is simply called or used (“If it looks like a duck and quacks like a duck, it must be a duck.”) By emphasizing interfaces rather than specific types, well-designed code improves its flexibility by allowing polymorphic substitution. Duck-typing avoids tests using type() or isinstance(). (Note, however, that duck-typing can be complemented with abstract base classes.) Instead, it typically employs hasattr() tests or EAFP programming. 

file object & file-like object

提供了open(),write(),read()方法的对象

function & method

定义在外边的函数叫function

定义在类中的函数叫method

finder 
An object that tries to find the loader for a module. It must implement either a method named find_loader() or a method named find_module(). See PEP 302 and PEP 420 for details and importlib.abc.Finder for an abstract base class. 

loader 
An object that loads a module. It must define a method named load_module(). A loader is typically returned by a finder. See PEP 302 for details and importlib.abc.Loader for an abstract base class. 

path entry 
A single location on the import path which the path based finder consults to find modules for importing. 
path entry finder 
A finder returned by a callable on sys.path_hooks (i.e. a path entry hook) which knows how to locate modules given a path entry. 
path entry hook 
A callable on the sys.path_hook list which returns a path entry finder if it knows how to find modules on a specific path entry. 
path based finder 
One of the default meta path finders which searches an import path for modules.
floor division 
Mathematical division that rounds down to nearest integer. The floor division operator is //. For example, the expression 11 // 4 evaluates to 2 in contrast to the 2.75 returned by float true division. Note that (-11) // 4 is -3 because that is -2.75 rounded downward. See PEP 238. 
function annotation 
An arbitrary metadata value associated with a function parameter or return value. Its syntax is explained in section Function definitions. Annotations may be accessed via the __annotations__ special attribute of a function object.
Python itself does not assign any particular meaning to function annotations. They are intended to be interpreted by third-party libraries or tools. See PEP 3107, which describes some of their potential uses.
__future__ 
从Python2.1开始,当一个新的语言特性首次出现在发行版中时,如果该特性与旧版Python不兼容,则该特性将被默认禁用。使用dir(__future__)可以看到有哪些功能。要启用这些特性,使用语句 ’from __future__ import *‘。

generator 
A function which returns an iterator. It looks like a normal function except that it contains yield statements for producing a series a values usable in a for-loop or that can be retrieved one at a time with the next() function. Each yield temporarily suspends processing, remembering the location execution state (including local variables and pending try-statements). When the generator resumes, it picks-up where it left-off (in contrast to functions which start fresh on every invocation). 
generator expression 
An expression that returns an iterator. It looks like a normal expression followed by a for expression defining a loop variable, range, and an optional if expression. The combined expression generates values for an enclosing function:
>>> sum(i*i for i in range(10))         # sum of squares 0, 1, 4, ... 81
285
generic function 
A function composed of multiple functions implementing the same operation for different types. Which implementation should be used during a call is determined by the dispatch algorithm.
See also the single dispatch glossary entry, the functools.singledispatch() decorator, and PEP 443.
hashable 
An object is hashable if it has a hash value which never changes during its lifetime (it needs a __hash__() method), and can be compared to other objects (it needs an __eq__() method). Hashable objects which compare equal must have the same hash value.
Hashability makes an object usable as a dictionary key and a set member, because these data structures use the hash value internally.
All of Python’s immutable built-in objects are hashable, while no mutable containers (such as lists or dictionaries) are. Objects which are instances of user-defined classes are hashable by default; they all compare unequal (except with themselves), and their hash value is their id().
immutable & mutable
immutable 不可变的,比如元组
mutable 可变的,比如list,dict

import path 
A list of locations (or path entries) that are searched by the path based finder for modules to import. During import, this list of locations usually comes from sys.path, but for subpackages it may also come from the parent package’s __path__ attribute. 
importing 
The process by which Python code in one module is made available to Python code in another module. 
importer 
An object that both finds and loads a module; both a finder and loader object. 

key function 
A key function or collation function
is a callable that returns a value used for sorting or ordering. For example, locale.strxfrm() is used to produce a sort key that is aware of locale specific sort conventions.
A number of tools in Python accept key functions to control how elements are ordered or grouped. They include min(), max(), sorted(), list.sort(), heapq.nsmallest(), heapq.nlargest(), and itertools.groupby().
There are several ways to create a key function. For example. the str.lower() method can serve as a key function for case insensitive sorts. Alternatively, an ad-hoc key function can be built from a lambda expression such as lambda r: (r[0], r[2]). Also, the operator module provides three key function constructors: attrgetter(), itemgetter(), and methodcaller(). See the Sorting HOW TO for examples of how to create and use key functions.

list comprehension 列表推导?深列表
A compact way to process all or part of the elements in a sequence and return a list with the results. result = ['{:#04x}'.format(x) for x in range(256) if x % 2 == 0] generates a list of strings containing even hex numbers (0x..) in the range from 0 to 255. The if clause is optional. If omitted, all elements in range(256) are processed. 

L1 = [1,2,3,4]

L2 = [i for i L1 if i!=2]

meta path finder 
A finder returned by a search of sys.meta_path. Meta path finders are related to, but different from path entry finders. 
metaclass 
The class of a class. Class definitions create a class name, a class dictionary, and a list of base classes. The metaclass is responsible for taking those three arguments and creating the class. Most object oriented programming languages provide a default implementation. What makes Python special is that it is possible to create custom metaclasses. Most users never need this tool, but when the need arises, metaclasses can provide powerful, elegant solutions. They have been used for logging attribute access, adding thread-safety, tracking object creation, implementing singletons, and many other tasks.

named tuple 
Any tuple-like class whose indexable elements are also accessible using named attributes (for example, time.localtime() returns a tuple-like object where the year is accessible either with an index such as t[0] or with a named attribute like t.tm_year).
A named tuple can be a built-in type such as time.struct_time, or it can be created with a regular class definition. A full featured named tuple can also be created with the factory function collections.namedtuple(). The latter approach automatically provides extra features such as a self-documenting representation like Employee(name='jones', title='programmer').
nested scope 
The ability to refer to a variable in an enclosing definition. For instance, a function defined inside another function can refer to variables in the outer function. Note that nested scopes by default work only for reference and not for assignment. Local variables both read and write in the innermost scope. Likewise, global variables read and write to the global namespace. The nonlocal allows writing to outer scopes. 

provisional API & provisional package 

 provision [prə'vɪʒn] 供应; 预备; 设备; 准备 
A provisional API is one which has been deliberately excluded from the standard library’s backwards compatibility guarantees. While major changes to such interfaces are not expected, as long as they are marked provisional, backwards incompatible changes (up to and including removal of the interface) may occur if deemed necessary by core developers. Such changes will
Even for provisional APIs, backwards incompatible changes are seen as a “solution of last resort” - every attempt will still be made to find a backwards compatible resolution to any identified problems.
This process allows the standard library to continue to evolve over time, without locking in problematic design errors for extended periods of time. See PEP 411 for more details.

qualified name 
A dotted name showing the “path” from a module’s global scope to a class, function or method defined in that module, as defined in PEP 3155. For top-level functions and classes, the qualified name is the same as the object’s name:
>>> class C:
...     class D:
...         def meth(self):
...             pass
...
>>> C.__qualname__
'C'
>>> C.D.__qualname__
'C.D'
>>> C.D.meth.__qualname__
'C.D.meth'
When used to refer to modules, the fully qualified name means the entire dotted path to the module, including any parent packages, e.g. email.mime.text:
>>> import email.mime.text
>>> email.mime.text.__name__
'email.mime.text'

__slots__ 
默认情况下类中的属性时用dict存储的,dict占用空间大,如果某个类需要进行大量使用的时候,定义了__slots__后就不会将变量放进dict中,会节约一定的空间。

A declaration inside a class that saves memory by pre-declaring space for instance attributes and eliminating instance dictionaries. Though popular, the technique is somewhat tricky to get right and is best reserved for rare cases where there are large numbers of instances in a memory-critical application. 

sequence 
An iterable which supports efficient element access using integer indices via the __getitem__() special method and defines a __len__() method that returns the length of the sequence. Some built-in sequence types are list, str, tuple, and bytes. Note that dict also supports __getitem__() and __len__(), but is considered a mapping rather than a sequence because the lookups use arbitrary immutable keys rather than integers.
The collections.abc.Sequence abstract base class defines a much richer interface that goes beyond just __getitem__() and __len__(), adding count(), index(), __contains__(), and __reversed__(). Types that implement this expanded interface can be registered explicitly using register().

single dispatch 
A form of generic function dispatch where the implementation is chosen based on the type of a single argument. 
special method 
A method that is called implicitly by Python to execute a certain operation on a type, such as addition. Such methods have names starting and ending with double underscores. Special methods are documented in Special method names. 
single dispatch 
A form of generic function dispatch where the implementation is chosen based on the type of a single argument. 
special method 
A method that is called implicitly by Python to execute a certain operation on a type, such as addition. Such methods have names starting and ending with double underscores. Special methods are documented in Special method names. 
struct sequence 
A tuple with named elements. Struct sequences expose an interface similar to named tuple in that elements can either be accessed either by index or as an attribute. However, they do not have any of the named tuple methods like _make() or _asdict(). Examples of struct sequences include sys.float_info and the return value of os.stat(). 
type 
The type of a Python object determines what kind of object it is; every object has a type. An object’s type is accessible as its __class__ attribute or can be retrieved with type(obj). 
universal newlines 
A manner of interpreting text streams in which all of the following are recognized as ending a line: the Unix end-of-line convention '\n', the Windows convention '\r\n', and the old Macintosh convention '\r'. See PEP 278 and PEP 3116, as well as str.splitlines() for an additional use. 
view 
The objects returned from dict.keys(), dict.values(), and dict.items() are called dictionary views. They are lazy sequences that will see changes in the underlying dictionary. To force the dictionary view to become a full list use list(dictview). See Dictionary view objects. 
Zen of Python Python之禅
Listing of Python design principles and philosophies that are helpful in understanding and using the language. The listing can be found by typing “import this” at the interactive prompt.

<完>

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值