@@ -294,6 +294,7 @@ msgid ""
294
294
"An interactive session shows that all access to the managed attribute *age* "
295
295
"is logged, but that the regular attribute *name* is not logged:"
296
296
msgstr ""
297
+ "互動式工作階段顯示對受管理屬性 *age* 的所有存取都被記錄,但一般屬性 *name* 則不會被記錄:"
297
298
298
299
#: ../../howto/descriptor.rst:181
299
300
msgid ""
@@ -332,6 +333,7 @@ msgid ""
332
333
"only have one logged attribute and that its name is unchangeable. In the "
333
334
"next example, we'll fix that problem."
334
335
msgstr ""
336
+ "這個範例的一個主要問題是私有名稱 *_age* 在 *LoggedAgeAccess* 類別中是硬編碼的。這意味著每個實例只能有一個被記錄的屬性,而且它的名稱是不可變的。在下一個範例中,我們將修正這個問題。"
335
337
336
338
#: ../../howto/descriptor.rst:213
337
339
msgid "Customized names"
@@ -352,6 +354,7 @@ msgid ""
352
354
"names can be recorded, giving each descriptor its own *public_name* and "
353
355
"*private_name*:"
354
356
msgstr ""
357
+ "在這個範例中,:class:`!Person` 類別有兩個描述器實例:*name* 和 *age*。當定義 :class:`!Person` 類別時,它會對 *LoggedAccess* 中的 :meth:`~object.__set_name__` 進行回呼,以便記錄欄位名稱,讓每個描述器都有自己的 *public_name* 和 *private_name*:"
355
358
356
359
#: ../../howto/descriptor.rst:223
357
360
msgid ""
@@ -462,32 +465,37 @@ msgid ""
462
465
"where it was created or the name of class variable it was assigned to. "
463
466
"(This method, if present, is called even if the class is not a descriptor.)"
464
467
msgstr ""
468
+ "描述器可以選擇性地擁有 :meth:`~object.__set_name__` 方法。這只在描述器需要知道建立它的類別或被指派的類別變數名稱時使用。(此方法如果存在,即使類別不是描述器也會被呼叫。)"
465
469
466
470
#: ../../howto/descriptor.rst:305
467
471
msgid ""
468
472
"Descriptors get invoked by the dot operator during attribute lookup. If a "
469
473
"descriptor is accessed indirectly with ``vars(some_class)"
470
474
"[descriptor_name]``, the descriptor instance is returned without invoking it."
471
475
msgstr ""
476
+ "描述器在屬性查找期間由點運算子呼叫。如果描述器是透過 ``vars(some_class)[descriptor_name]`` 間接存取,會回傳描述器實例而不呼叫它。"
472
477
473
478
#: ../../howto/descriptor.rst:309
474
479
msgid ""
475
480
"Descriptors only work when used as class variables. When put in instances, "
476
481
"they have no effect."
477
482
msgstr ""
483
+ "描述器只有在用作類別變數時才能運作。當放在實例中時,它們沒有效果。"
478
484
479
485
#: ../../howto/descriptor.rst:312
480
486
msgid ""
481
487
"The main motivation for descriptors is to provide a hook allowing objects "
482
488
"stored in class variables to control what happens during attribute lookup."
483
489
msgstr ""
490
+ "描述器的主要動機是提供一個掛鉤,讓儲存在類別變數中的物件能夠控制屬性查找期間發生的事情。"
484
491
485
492
#: ../../howto/descriptor.rst:315
486
493
msgid ""
487
494
"Traditionally, the calling class controls what happens during lookup. "
488
495
"Descriptors invert that relationship and allow the data being looked-up to "
489
496
"have a say in the matter."
490
497
msgstr ""
498
+ "傳統上,呼叫的類別控制查找期間發生的事情。描述器顛倒了這種關係,讓被查找的資料在這件事上有發言權。"
491
499
492
500
#: ../../howto/descriptor.rst:319
493
501
msgid ""
@@ -496,6 +504,7 @@ msgid ""
496
504
"like :func:`classmethod`, :func:`staticmethod`, :func:`property`, "
497
505
"and :func:`functools.cached_property` are all implemented as descriptors."
498
506
msgstr ""
507
+ "描述器在整個語言中被廣泛使用。函式就是透過這種方式轉變為綁定方法。常見工具如 :func:`classmethod`、:func:`staticmethod`、:func:`property` 和 :func:`functools.cached_property` 都是以描述器實作的。"
499
508
500
509
#: ../../howto/descriptor.rst:326
501
510
msgid "Complete Practical Example"
0 commit comments