“Python/docs/3.9/c-api/concrete”的版本间差异

来自菜鸟教程
Python/docs/3.9/c-api/concrete
跳转至:导航、​搜索
(autoload)
 
(Page commit)
 
第1行: 第1行:
 +
{{DISPLAYTITLE:具体对象层 — Python 文档}}
 
<div id="concrete-objects-layer" class="section">
 
<div id="concrete-objects-layer" class="section">
  
 
<span id="concrete"></span>
 
<span id="concrete"></span>
= Concrete Objects Layer =
+
= 具体对象层 =
  
The functions in this chapter are specific to certain Python object types.
+
本章中的函数特定于某些 Python 对象类型。 向它们传递错误类型的对象不是一个好主意; 如果您从 Python 程序接收到一个对象,但您不确定它的类型是否正确,则必须先执行类型检查; 例如,要检查对象是否是字典,请使用 [[../dict#c|PyDict_Check()]]。 本章的结构类似于 Python 对象类型的“家谱”。
Passing them an object of the wrong type is not a good idea; if you receive an
 
object from a Python program and you are not sure that it has the right type,
 
you must perform a type check first; for example, to check that an object is a
 
dictionary, use [[../dict#c|<code>PyDict_Check()</code>]]. The chapter is structured like the
 
&quot;family tree&quot; of Python object types.
 
  
 
<div class="admonition warning">
 
<div class="admonition warning">
第15行: 第11行:
 
警告
 
警告
  
While the functions described in this chapter carefully check the type of the
+
虽然本章中描述的函数会仔细检查传入的对象的类型,但其中许多函数不会检查传递的是 <code>NULL</code> 而不是有效对象。 允许传入 <code>NULL</code> 会导致内存访问冲突并立即终止解释器。
objects which are passed in, many of them do not check for <code>NULL</code> being passed
 
instead of a valid object. Allowing <code>NULL</code> to be passed in can cause memory
 
access violations and immediate termination of the interpreter.
 
  
  
第25行: 第18行:
  
 
<span id="fundamental"></span>
 
<span id="fundamental"></span>
== Fundamental Objects ==
+
== 基本对象 ==
  
This section describes Python type objects and the singleton object <code>None</code>.
+
本节介绍 Python 类型对象和单例对象 <code>None</code>
  
 
<div class="toctree-wrapper compound">
 
<div class="toctree-wrapper compound">
  
* [[../type|Type Objects]]
+
* [[../type|类型对象]]
** [[../type#creating-heap-allocated-types|Creating Heap-Allocated Types]]
+
** [[../type#creating-heap-allocated-types|创建堆分配类型]]
* [[../none|The <code>None</code> Object]]
+
* [[../none|<code>None</code> 对象]]
  
  
第42行: 第35行:
  
 
<span id="numericobjects"></span>
 
<span id="numericobjects"></span>
== Numeric Objects ==
+
== 数字对象 ==
  
 
<div id="index-0" class="toctree-wrapper compound">
 
<div id="index-0" class="toctree-wrapper compound">
  
* [[../long|Integer Objects]]
+
* [[../long|整数对象]]
* [[../bool|Boolean Objects]]
+
* [[../bool|布尔对象]]
* [[../float|Floating Point Objects]]
+
* [[../float|浮点对象]]
* [[../complex|Complex Number Objects]]
+
* [[../complex|复数对象]]
** [[../complex#complex-numbers-as-c-structures|Complex Numbers as C Structures]]
+
** [[../complex#complex-numbers-as-c-structures|作为 C 结构的复数]]
** [[../complex#complex-numbers-as-python-objects|Complex Numbers as Python Objects]]
+
** [[../complex#complex-numbers-as-python-objects|复数作为 Python 对象]]
  
  
第60行: 第53行:
  
 
<span id="sequenceobjects"></span>
 
<span id="sequenceobjects"></span>
== Sequence Objects ==
+
== 序列对象 ==
  
Generic operations on sequence objects were discussed in the previous chapter;
+
序列对象的泛型操作在前一章中讨论过; 本节讨论 Python 语言固有的特定类型的序列对象。
this section deals with the specific kinds of sequence objects that are
 
intrinsic to the Python language.
 
  
 
<div class="toctree-wrapper compound">
 
<div class="toctree-wrapper compound">
  
* [[../bytes|Bytes Objects]]
+
* [[../bytes|字节对象]]
* [[../bytearray|Byte Array Objects]]
+
* [[../bytearray|字节数组对象]]
** [[../bytearray#type-check-macros|Type check macros]]
+
** [[../bytearray#type-check-macros|类型检查宏]]
** [[../bytearray#direct-api-functions|Direct API functions]]
+
** [[../bytearray#direct-api-functions|直接 API 函数]]
** [[../bytearray#macros|Macros]]
+
** [[../bytearray#macros|]]
* [[../unicode|Unicode Objects and Codecs]]
+
* [[../unicode|Unicode 对象和编解码器]]
** [[../unicode#unicode-objects|Unicode Objects]]
+
** [[../unicode#unicode-objects|Unicode 对象]]
*** [[../unicode#unicode-type|Unicode Type]]
+
*** [[../unicode#unicode-type|Unicode 类型]]
*** [[../unicode#unicode-character-properties|Unicode Character Properties]]
+
*** [[../unicode#unicode-character-properties|Unicode 字符属性]]
*** [[../unicode#creating-and-accessing-unicode-strings|Creating and accessing Unicode strings]]
+
*** [[../unicode#creating-and-accessing-unicode-strings|创建和访问 Unicode 字符串]]
*** [[../unicode#deprecated-py-unicode-apis|Deprecated Py_UNICODE APIs]]
+
*** [[../unicode#deprecated-py-unicode-apis|已弃用的 Py_UNICODE API]]
*** [[../unicode#locale-encoding|Locale Encoding]]
+
*** [[../unicode#locale-encoding|语言环境编码]]
*** [[../unicode#file-system-encoding|File System Encoding]]
+
*** [[../unicode#file-system-encoding|文件系统编码]]
*** [[../unicode#wchar-t-support|wchar_t Support]]
+
*** [[../unicode#wchar-t-support|wchar_t 支持]]
** [[../unicode#built-in-codecs|Built-in Codecs]]
+
** [[../unicode#built-in-codecs|内置编解码器]]
*** [[../unicode#generic-codecs|Generic Codecs]]
+
*** [[../unicode#generic-codecs|通用编解码器]]
*** [[../unicode#utf-8-codecs|UTF-8 Codecs]]
+
*** [[../unicode#utf-8-codecs|UTF-8 编解码器]]
*** [[../unicode#utf-32-codecs|UTF-32 Codecs]]
+
*** [[../unicode#utf-32-codecs|UTF-32 编解码器]]
*** [[../unicode#utf-16-codecs|UTF-16 Codecs]]
+
*** [[../unicode#utf-16-codecs|UTF-16 编解码器]]
*** [[../unicode#utf-7-codecs|UTF-7 Codecs]]
+
*** [[../unicode#utf-7-codecs|UTF-7 编解码器]]
*** [[../unicode#unicode-escape-codecs|Unicode-Escape Codecs]]
+
*** [[../unicode#unicode-escape-codecs|Unicode 转义编解码器]]
*** [[../unicode#raw-unicode-escape-codecs|Raw-Unicode-Escape Codecs]]
+
*** [[../unicode#raw-unicode-escape-codecs|原始 Unicode 转义编解码器]]
*** [[../unicode#latin-1-codecs|Latin-1 Codecs]]
+
*** [[../unicode#latin-1-codecs|拉丁 1 编解码器]]
*** [[../unicode#ascii-codecs|ASCII Codecs]]
+
*** [[../unicode#ascii-codecs|ASCII 编解码器]]
*** [[../unicode#character-map-codecs|Character Map Codecs]]
+
*** [[../unicode#character-map-codecs|字符映射编解码器]]
*** [[../unicode#mbcs-codecs-for-windows|MBCS codecs for Windows]]
+
*** [[../unicode#mbcs-codecs-for-windows|适用于 Windows 的 MBCS 编解码器]]
*** [[../unicode#methods-slots|Methods &amp; Slots]]
+
*** [[../unicode#methods-slots|方法和插槽]]
** [[../unicode#methods-and-slot-functions|Methods and Slot Functions]]
+
** [[../unicode#methods-and-slot-functions|方法和槽函数]]
* [[../tuple|Tuple Objects]]
+
* [[../tuple|元组对象]]
* [[../tuple#struct-sequence-objects|Struct Sequence Objects]]
+
* [[../tuple#struct-sequence-objects|结构序列对象]]
* [[../list|List Objects]]
+
* [[../list|列出对象]]
  
  
第107行: 第98行:
  
 
<span id="mapobjects"></span>
 
<span id="mapobjects"></span>
== Container Objects ==
+
== 容器对象 ==
  
 
<div id="index-2" class="toctree-wrapper compound">
 
<div id="index-2" class="toctree-wrapper compound">
  
* [[../dict|Dictionary Objects]]
+
* [[../dict|字典对象]]
* [[../set|Set Objects]]
+
* [[../set|设置对象]]
  
  
第121行: 第112行:
  
 
<span id="otherobjects"></span>
 
<span id="otherobjects"></span>
== Function Objects ==
+
== 函数对象 ==
  
 
<div class="toctree-wrapper compound">
 
<div class="toctree-wrapper compound">
  
* [[../function|Function Objects]]
+
* [[../function|函数对象]]
* [[../method|Instance Method Objects]]
+
* [[../method|实例方法对象]]
* [[../method#method-objects|Method Objects]]
+
* [[../method#method-objects|方法对象]]
* [[../cell|Cell Objects]]
+
* [[../cell|单元格对象]]
* [[../code|Code Objects]]
+
* [[../code|代码对象]]
  
  
第137行: 第128行:
 
<div id="other-objects" class="section">
 
<div id="other-objects" class="section">
  
== Other Objects ==
+
== 其他对象 ==
  
 
<div class="toctree-wrapper compound">
 
<div class="toctree-wrapper compound">
  
* [[../file|File Objects]]
+
* [[../file|文件对象]]
* [[../module|Module Objects]]
+
* [[../module|模块对象]]
** [[../module#initializing-c-modules|Initializing C modules]]
+
** [[../module#initializing-c-modules|初始化 C 模块]]
*** [[../module#single-phase-initialization|Single-phase initialization]]
+
*** [[../module#single-phase-initialization|单相初始化]]
*** [[../module#multi-phase-initialization|Multi-phase initialization]]
+
*** [[../module#multi-phase-initialization|多阶段初始化]]
*** [[../module#low-level-module-creation-functions|Low-level module creation functions]]
+
*** [[../module#low-level-module-creation-functions|低级模块创建函数]]
*** [[../module#support-functions|Support functions]]
+
*** [[../module#support-functions|支持功能]]
** [[../module#module-lookup|Module lookup]]
+
** [[../module#module-lookup|模块查找]]
* [[../iterator|Iterator Objects]]
+
* [[../iterator|迭代器对象]]
* [[../descriptor|Descriptor Objects]]
+
* [[../descriptor|描述符对象]]
* [[../slice|Slice Objects]]
+
* [[../slice|切片对象]]
* [[../slice#ellipsis-object|Ellipsis Object]]
+
* [[../slice#ellipsis-object|省略号对象]]
* [[../memoryview|MemoryView objects]]
+
* [[../memoryview|内存视图对象]]
* [[../weakref|Weak Reference Objects]]
+
* [[../weakref|弱引用对象]]
* [[../capsule|Capsules]]
+
* [[../capsule|胶囊]]
* [[../gen|Generator Objects]]
+
* [[../gen|生成器对象]]
* [[../coro|Coroutine Objects]]
+
* [[../coro|协程对象]]
* [[../contextvars|Context Variables Objects]]
+
* [[../contextvars|上下文变量对象]]
* [[../datetime|DateTime Objects]]
+
* [[../datetime|日期时间对象]]
 +
* [[../typehints|类型提示的对象]]
  
  
第167行: 第159行:
  
 
</div>
 
</div>
 +
<div class="clearer">
  
[[Category:Python 3.9 中文文档]]
+
 
 +
 
 +
</div>
 +
 
 +
[[Category:Python 3.9 文档]]

2021年10月31日 (日) 04:50的最新版本

具体对象层

本章中的函数特定于某些 Python 对象类型。 向它们传递错误类型的对象不是一个好主意; 如果您从 Python 程序接收到一个对象,但您不确定它的类型是否正确,则必须先执行类型检查; 例如,要检查对象是否是字典,请使用 PyDict_Check()。 本章的结构类似于 Python 对象类型的“家谱”。

警告

虽然本章中描述的函数会仔细检查传入的对象的类型,但其中许多函数不会检查传递的是 NULL 而不是有效对象。 允许传入 NULL 会导致内存访问冲突并立即终止解释器。


基本对象

本节介绍 Python 类型对象和单例对象 None

容器对象