-
-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathexpressions.po
2426 lines (2108 loc) · 127 KB
/
expressions.po
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# SOME DESCRIPTIVE TITLE.
# Copyright (C) 2001-2024, Python Software Foundation
# This file is distributed under the same license as the Python package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
# Translators:
# eric R <trencyclopedia@gmail.com>, 2020
# dannyvi <dannyvis@icloud.com>, 2020
# Pan Felix <tinylambda@gmail.com>, 2020
# 操旭 <caoxu3000@126.com>, 2020
# Fred <fred.wei@foxmail.com>, 2020
# nick <2330458484@qq.com>, 2020
# Freesand Leo <yuqinju@163.com>, 2022
# Rafael Fontenelle <rffontenelle@gmail.com>, 2024
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: Python 3.8\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-07-29 06:43+0000\n"
"PO-Revision-Date: 2020-05-30 12:15+0000\n"
"Last-Translator: Rafael Fontenelle <rffontenelle@gmail.com>, 2024\n"
"Language-Team: Chinese (China) (https://app.transifex.com/python-doc/teams/5390/zh_CN/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: zh_CN\n"
"Plural-Forms: nplurals=1; plural=0;\n"
#: ../../reference/expressions.rst:6
msgid "Expressions"
msgstr "表达式"
#: ../../reference/expressions.rst:10
msgid ""
"This chapter explains the meaning of the elements of expressions in Python."
msgstr "本章将解释 Python 中组成表达式的各种元素的的含义。"
#: ../../reference/expressions.rst:12
msgid ""
"**Syntax Notes:** In this and the following chapters, extended BNF notation "
"will be used to describe syntax, not lexical analysis. When (one "
"alternative of) a syntax rule has the form"
msgstr "**语法注释:** 在本章和后续章节中,会使用扩展 BNF 标注来描述语法而不是词法分析。 当(某种替代的)语法规则具有如下形式"
#: ../../reference/expressions.rst:19
msgid ""
"and no semantics are given, the semantics of this form of ``name`` are the "
"same as for ``othername``."
msgstr "并且没有给出语义,则这种形式的 ``name`` 在语法上与 ``othername`` 相同。"
#: ../../reference/expressions.rst:26
msgid "Arithmetic conversions"
msgstr "算术转换"
#: ../../reference/expressions.rst:30
msgid ""
"When a description of an arithmetic operator below uses the phrase \"the "
"numeric arguments are converted to a common type\", this means that the "
"operator implementation for built-in types works as follows:"
msgstr "当对下述某个算术运算符的描述中使用了“数值参数被转换为普通类型”这样的说法,这意味着内置类型的运算符实现采用了如下运作方式:"
#: ../../reference/expressions.rst:34
msgid ""
"If either argument is a complex number, the other is converted to complex;"
msgstr "如果任一参数为复数,另一参数会被转换为复数;"
#: ../../reference/expressions.rst:36
msgid ""
"otherwise, if either argument is a floating point number, the other is "
"converted to floating point;"
msgstr "否则,如果任一参数为浮点数,另一参数会被转换为浮点数;"
#: ../../reference/expressions.rst:39
msgid "otherwise, both must be integers and no conversion is necessary."
msgstr "否则,两者应该都为整数,不需要进行转换。"
#: ../../reference/expressions.rst:41
msgid ""
"Some additional rules apply for certain operators (e.g., a string as a left "
"argument to the '%' operator). Extensions must define their own conversion "
"behavior."
msgstr "某些附加规则会作用于特定运算符(例如,字符串作为 '%' 运算符的左运算参数)。 扩展必须定义它们自己的转换行为。"
#: ../../reference/expressions.rst:49
msgid "Atoms"
msgstr "原子"
#: ../../reference/expressions.rst:53
msgid ""
"Atoms are the most basic elements of expressions. The simplest atoms are "
"identifiers or literals. Forms enclosed in parentheses, brackets or braces "
"are also categorized syntactically as atoms. The syntax for atoms is:"
msgstr ""
"“原子”指表达式的最基本构成元素。 最简单的原子是标识符和字面值。 以圆括号、方括号或花括号包括的形式在语法上也被归类为原子。 原子的句法为:"
#: ../../reference/expressions.rst:66
msgid "Identifiers (Names)"
msgstr "标识符(名称)"
#: ../../reference/expressions.rst:70
msgid ""
"An identifier occurring as an atom is a name. See section "
":ref:`identifiers` for lexical definition and section :ref:`naming` for "
"documentation of naming and binding."
msgstr ""
"作为原子出现的标识符叫做名称。 请参看 :ref:`identifiers` 一节了解其词法定义,以及 :ref:`naming` "
"获取有关命名与绑定的文档。"
#: ../../reference/expressions.rst:76
msgid ""
"When the name is bound to an object, evaluation of the atom yields that "
"object. When a name is not bound, an attempt to evaluate it raises a "
":exc:`NameError` exception."
msgstr "当名称被绑定到一个对象时,对该原子求值将返回相应对象。 当名称未被绑定时,尝试对其求值将引发 :exc:`NameError` 异常。"
#: ../../reference/expressions.rst:84
msgid ""
"**Private name mangling:** When an identifier that textually occurs in a "
"class definition begins with two or more underscore characters and does not "
"end in two or more underscores, it is considered a :dfn:`private name` of "
"that class. Private names are transformed to a longer form before code is "
"generated for them. The transformation inserts the class name, with leading"
" underscores removed and a single underscore inserted, in front of the name."
" For example, the identifier ``__spam`` occurring in a class named ``Ham`` "
"will be transformed to ``_Ham__spam``. This transformation is independent "
"of the syntactical context in which the identifier is used. If the "
"transformed name is extremely long (longer than 255 characters), "
"implementation defined truncation may happen. If the class name consists "
"only of underscores, no transformation is done."
msgstr ""
"**私有名称转换:** 当以文本形式出现在类定义中的一个标识符以两个或更多下划线开头并且不以两个或更多下划线结尾,它会被视为该类的 "
":dfn:`私有名称`。 私有名称会在为其生成代码之前被转换为一种更长的形式。 转换时会插入类名,移除打头的下划线再在名称前增加一个下划线。 "
"例如,出现在一个名为 ``Ham`` 的类中的标识符 ``__spam`` 会被转换为 ``_Ham__spam``。 "
"这种转换独立于标识符所使用的相关句法。 如果转换后的名称太长(超过 255 个字符),可能发生由具体实现定义的截断。 "
"如果类名仅由下划线组成,则不会进行转换。"
#: ../../reference/expressions.rst:100
msgid "Literals"
msgstr "字面值"
#: ../../reference/expressions.rst:104
msgid ""
"Python supports string and bytes literals and various numeric literals:"
msgstr "Python 支持字符串和字节串字面值,以及几种数字字面值:"
#: ../../reference/expressions.rst:110
msgid ""
"Evaluation of a literal yields an object of the given type (string, bytes, "
"integer, floating point number, complex number) with the given value. The "
"value may be approximated in the case of floating point and imaginary "
"(complex) literals. See section :ref:`literals` for details."
msgstr ""
"对字面值求值将返回一个该值所对应类型的对象(字符串、字节串、整数、浮点数、复数)。 对于浮点数和虚数(复数)的情况,该值可能为近似值。 详情参见 "
":ref:`literals`。"
#: ../../reference/expressions.rst:119
msgid ""
"All literals correspond to immutable data types, and hence the object's "
"identity is less important than its value. Multiple evaluations of literals"
" with the same value (either the same occurrence in the program text or a "
"different occurrence) may obtain the same object or a different object with "
"the same value."
msgstr ""
"所有字面值都对应于不可变数据类型,因此对象标识的重要性不如其实际值。 "
"多次对具有相同值的字面值求值(不论是发生在程序文本的相同位置还是不同位置)可能得到相同对象或是具有相同值的不同对象。"
#: ../../reference/expressions.rst:129
msgid "Parenthesized forms"
msgstr "带圆括号的形式"
#: ../../reference/expressions.rst:135
msgid ""
"A parenthesized form is an optional expression list enclosed in parentheses:"
msgstr "带圆括号的形式是包含在圆括号中的可选表达式列表。"
#: ../../reference/expressions.rst:140
msgid ""
"A parenthesized expression list yields whatever that expression list yields:"
" if the list contains at least one comma, it yields a tuple; otherwise, it "
"yields the single expression that makes up the expression list."
msgstr ""
"带圆括号的表达式列表将返回该表达式列表所产生的任何东西:如果该列表包含至少一个逗号,它会产生一个元组;否则,它会产生该表达式列表所对应的单一表达式。"
#: ../../reference/expressions.rst:146
msgid ""
"An empty pair of parentheses yields an empty tuple object. Since tuples are"
" immutable, the same rules as for literals apply (i.e., two occurrences of "
"the empty tuple may or may not yield the same object)."
msgstr ""
"一对内容为空的圆括号将产生一个空的元组对象。 由于元组是不可变对象,因此适用与字面值相同的规则(即两次出现的空元组产生的对象可能相同也可能不同)。"
#: ../../reference/expressions.rst:154
msgid ""
"Note that tuples are not formed by the parentheses, but rather by use of the"
" comma operator. The exception is the empty tuple, for which parentheses "
"*are* required --- allowing unparenthesized \"nothing\" in expressions would"
" cause ambiguities and allow common typos to pass uncaught."
msgstr ""
"请注意元组并不是由圆括号构建,实际起作用的是逗号操作符。 例外情况是空元组,这时圆括号 *才是* 必须的 --- 允许在表达式中使用不带圆括号的 "
"\"空\" 会导致歧义,并会造成常见输入错误无法被捕获。"
#: ../../reference/expressions.rst:163
msgid "Displays for lists, sets and dictionaries"
msgstr "列表、集合与字典的显示"
#: ../../reference/expressions.rst:167
msgid ""
"For constructing a list, a set or a dictionary Python provides special "
"syntax called \"displays\", each of them in two flavors:"
msgstr "为了构建列表、集合或字典,Python 提供了名为“显示”的特殊句法,每个类型各有两种形式:"
#: ../../reference/expressions.rst:170
msgid "either the container contents are listed explicitly, or"
msgstr "第一种是显式地列出容器内容"
#: ../../reference/expressions.rst:172
msgid ""
"they are computed via a set of looping and filtering instructions, called a "
":dfn:`comprehension`."
msgstr "第二种是通过一组循环和筛选指令计算出来,称为 :dfn:`推导式`。"
#: ../../reference/expressions.rst:180
msgid "Common syntax elements for comprehensions are:"
msgstr "推导式的常用句法元素为:"
#: ../../reference/expressions.rst:188
msgid ""
"The comprehension consists of a single expression followed by at least one "
":keyword:`!for` clause and zero or more :keyword:`!for` or :keyword:`!if` "
"clauses. In this case, the elements of the new container are those that "
"would be produced by considering each of the :keyword:`!for` or "
":keyword:`!if` clauses a block, nesting from left to right, and evaluating "
"the expression to produce an element each time the innermost block is "
"reached."
msgstr ""
"推导式的结构是一个单独表达式后面加至少一个 :keyword:`!for` 子句以及零个或更多个 :keyword:`!for` 或 "
":keyword:`!if` 子句。 在这种情况下,新容器的元素产生方式是将每个 :keyword:`!for` 或 :keyword:`!if` "
"子句视为一个代码块,按从左至右的顺序嵌套,然后每次到达最内层代码块时就对表达式进行求值以产生一个元素。"
#: ../../reference/expressions.rst:195
msgid ""
"However, aside from the iterable expression in the leftmost :keyword:`!for` "
"clause, the comprehension is executed in a separate implicitly nested scope."
" This ensures that names assigned to in the target list don't \"leak\" into "
"the enclosing scope."
msgstr ""
"不过,除了最左边 :keyword:`!for` 子句中的可迭代表达式,推导式是在另一个隐式嵌套的作用域内执行的。 "
"这能确保赋给目标列表的名称不会“泄露”到外层的作用域。"
#: ../../reference/expressions.rst:199
msgid ""
"The iterable expression in the leftmost :keyword:`!for` clause is evaluated "
"directly in the enclosing scope and then passed as an argument to the "
"implicitly nested scope. Subsequent :keyword:`!for` clauses and any filter "
"condition in the leftmost :keyword:`!for` clause cannot be evaluated in the "
"enclosing scope as they may depend on the values obtained from the leftmost "
"iterable. For example: ``[x*y for x in range(10) for y in range(x, x+10)]``."
msgstr ""
"最左边的 :keyword:`!for` 子句中的可迭代对象表达式会直接在外层作用域中被求值,然后作为一个参数被传给隐式嵌套的作用域。 后续的 "
":keyword:`!for` 子句以及最左侧 :keyword:`!for` "
"子句中的任何筛选条件不能在外层作用域中被求值,因为它们可能依赖于从最左侧可迭代对象中获得的值。 例如: ``[x*y for x in "
"range(10) for y in range(x, x+10)]``。"
#: ../../reference/expressions.rst:206
msgid ""
"To ensure the comprehension always results in a container of the appropriate"
" type, ``yield`` and ``yield from`` expressions are prohibited in the "
"implicitly nested scope."
msgstr "为了确保推导式得出的结果总是一个类型正确的容器,在隐式嵌套作用域内禁止使用 ``yield`` 和 ``yield from`` 表达式。"
#: ../../reference/expressions.rst:213
msgid ""
"Since Python 3.6, in an :keyword:`async def` function, an :keyword:`!async "
"for` clause may be used to iterate over a :term:`asynchronous iterator`. A "
"comprehension in an :keyword:`!async def` function may consist of either a "
":keyword:`!for` or :keyword:`!async for` clause following the leading "
"expression, may contain additional :keyword:`!for` or :keyword:`!async for` "
"clauses, and may also use :keyword:`await` expressions. If a comprehension "
"contains either :keyword:`!async for` clauses or :keyword:`!await` "
"expressions it is called an :dfn:`asynchronous comprehension`. An "
"asynchronous comprehension may suspend the execution of the coroutine "
"function in which it appears. See also :pep:`530`."
msgstr ""
"从 Python 3.6 开始,在 :keyword:`async def` 函数中可以使用 :keyword:`!async for` 子句来迭代 "
":term:`asynchronous iterator`。 在 :keyword:`!async def` "
"函数中构建推导式可以通过在打头的表达式后加上 :keyword:`!for` 或 :keyword:`!async for` 子句,也可能包含额外的 "
":keyword:`!for` 或 :keyword:`!async for` 子句,还可能使用 :keyword:`await` 表达式。 "
"如果一个推导式包含 :keyword:`!async for` 子句或者 :keyword:`!await` 表达式,则被称为 "
":dfn:`异步推导式`。 异步推导式可以暂停执行它所在的协程函数。 另请参阅 :pep:`530`。"
#: ../../reference/expressions.rst:225
msgid "Asynchronous comprehensions were introduced."
msgstr "引入了异步推导式。"
#: ../../reference/expressions.rst:228 ../../reference/expressions.rst:401
msgid ""
"``yield`` and ``yield from`` prohibited in the implicitly nested scope."
msgstr "``yield`` 和 ``yield from`` 在隐式嵌套的作用域中已被禁用。"
#: ../../reference/expressions.rst:235
msgid "List displays"
msgstr "列表显示"
#: ../../reference/expressions.rst:245
msgid ""
"A list display is a possibly empty series of expressions enclosed in square "
"brackets:"
msgstr "列表显示是一个用方括号括起来的可能为空的表达式系列:"
#: ../../reference/expressions.rst:251
msgid ""
"A list display yields a new list object, the contents being specified by "
"either a list of expressions or a comprehension. When a comma-separated "
"list of expressions is supplied, its elements are evaluated from left to "
"right and placed into the list object in that order. When a comprehension "
"is supplied, the list is constructed from the elements resulting from the "
"comprehension."
msgstr ""
"列表显示会产生一个新的列表对象,其内容通过一系列表达式或一个推导式来指定。 "
"当提供由逗号分隔的一系列表达式时,其元素会从左至右被求值并按此顺序放入列表对象。 当提供一个推导式时,列表会根据推导式所产生的结果元素进行构建。"
#: ../../reference/expressions.rst:261
msgid "Set displays"
msgstr "集合显示"
#: ../../reference/expressions.rst:270
msgid ""
"A set display is denoted by curly braces and distinguishable from dictionary"
" displays by the lack of colons separating keys and values:"
msgstr "集合显示是用花括号标明的,与字典显示的区别在于没有冒号分隔的键和值:"
#: ../../reference/expressions.rst:276
msgid ""
"A set display yields a new mutable set object, the contents being specified "
"by either a sequence of expressions or a comprehension. When a comma-"
"separated list of expressions is supplied, its elements are evaluated from "
"left to right and added to the set object. When a comprehension is "
"supplied, the set is constructed from the elements resulting from the "
"comprehension."
msgstr ""
"集合显示会产生一个新的可变集合对象,其内容通过一系列表达式或一个推导式来指定。 "
"当提供由逗号分隔的一系列表达式时,其元素会从左至右被求值并加入到集合对象。 当提供一个推导式时,集合会根据推导式所产生的结果元素进行构建。"
#: ../../reference/expressions.rst:282
msgid ""
"An empty set cannot be constructed with ``{}``; this literal constructs an "
"empty dictionary."
msgstr "空集合不能用 ``{}`` 来构建;该字面值所构建的是一个空字典。"
#: ../../reference/expressions.rst:289
msgid "Dictionary displays"
msgstr "字典显示"
#: ../../reference/expressions.rst:300
msgid ""
"A dictionary display is a possibly empty series of key/datum pairs enclosed "
"in curly braces:"
msgstr "字典显示是一个用花括号括起来的可能为空的键/数据对系列:"
#: ../../reference/expressions.rst:309
msgid "A dictionary display yields a new dictionary object."
msgstr "字典显示会产生一个新的字典对象。"
#: ../../reference/expressions.rst:311
msgid ""
"If a comma-separated sequence of key/datum pairs is given, they are "
"evaluated from left to right to define the entries of the dictionary: each "
"key object is used as a key into the dictionary to store the corresponding "
"datum. This means that you can specify the same key multiple times in the "
"key/datum list, and the final dictionary's value for that key will be the "
"last one given."
msgstr ""
"如果给出一个由逗号分隔的键/数据对序列,它们会从左至右被求值以定义字典的条目:每个键对象会被用作在字典中存放相应数据的键。 "
"这意味着你可以在键/数据对序列中多次指定相同的键,最终字典的值将由最后一次给出的键决定。"
#: ../../reference/expressions.rst:321
msgid ""
"A double asterisk ``**`` denotes :dfn:`dictionary unpacking`. Its operand "
"must be a :term:`mapping`. Each mapping item is added to the new "
"dictionary. Later values replace values already set by earlier key/datum "
"pairs and earlier dictionary unpackings."
msgstr ""
"双星号 ``**`` 表示 :dfn:`字典拆包`。 它的操作数必须是一个 :term:`mapping`。 每个映射项被会加入新的字典。 "
"后续的值会替代先前的键/数据对和先前的字典拆包所设置的值。"
#: ../../reference/expressions.rst:326
msgid "Unpacking into dictionary displays, originally proposed by :pep:`448`."
msgstr "拆包到字典显示,最初由 :pep:`448` 提出。"
#: ../../reference/expressions.rst:329
msgid ""
"A dict comprehension, in contrast to list and set comprehensions, needs two "
"expressions separated with a colon followed by the usual \"for\" and \"if\" "
"clauses. When the comprehension is run, the resulting key and value elements"
" are inserted in the new dictionary in the order they are produced."
msgstr ""
"字典推导式与列表和集合推导式有所不同,它需要以冒号分隔的两个表达式,后面带上标准的 \"for\" 和 \"if\" 子句。 "
"当推导式被执行时,作为结果的键和值元素会按它们的产生顺序被加入新的字典。"
#: ../../reference/expressions.rst:337
msgid ""
"Restrictions on the types of the key values are listed earlier in section "
":ref:`types`. (To summarize, the key type should be :term:`hashable`, which"
" excludes all mutable objects.) Clashes between duplicate keys are not "
"detected; the last datum (textually rightmost in the display) stored for a "
"given key value prevails."
msgstr ""
"对键取值类型的限制已列在之前的 :ref:`types` 一节中。 (总的说来,键的类型应该为 "
":term:`hashable`,这就把所有可变对象都排除在外。) 重复键之间的冲突不会被检测;指定键所保存的最后一个数据 (即在显示中排最右边的文本)"
" 为最终有效数据。"
#: ../../reference/expressions.rst:343
msgid ""
"Prior to Python 3.8, in dict comprehensions, the evaluation order of key and"
" value was not well-defined. In CPython, the value was evaluated before the"
" key. Starting with 3.8, the key is evaluated before the value, as proposed"
" by :pep:`572`."
msgstr ""
"在 Python 3.8 之前的字典推导式中,并没有定义好键和值的求值顺序。 在 CPython 中,值会先于键被求值。 根据 :pep:`572` "
"的提议,从 3.8 开始,键会先于值被求值。"
#: ../../reference/expressions.rst:353
msgid "Generator expressions"
msgstr "生成器表达式"
#: ../../reference/expressions.rst:360
msgid "A generator expression is a compact generator notation in parentheses:"
msgstr "生成器表达式是用圆括号括起来的紧凑形式生成器标注。"
#: ../../reference/expressions.rst:365
msgid ""
"A generator expression yields a new generator object. Its syntax is the "
"same as for comprehensions, except that it is enclosed in parentheses "
"instead of brackets or curly braces."
msgstr "生成器表达式会产生一个新的生成器对象。 其句法与推导式相同,区别在于它是用圆括号而不是用方括号或花括号括起来的。"
#: ../../reference/expressions.rst:369
msgid ""
"Variables used in the generator expression are evaluated lazily when the "
":meth:`~generator.__next__` method is called for the generator object (in "
"the same fashion as normal generators). However, the iterable expression in"
" the leftmost :keyword:`!for` clause is immediately evaluated, so that an "
"error produced by it will be emitted at the point where the generator "
"expression is defined, rather than at the point where the first value is "
"retrieved. Subsequent :keyword:`!for` clauses and any filter condition in "
"the leftmost :keyword:`!for` clause cannot be evaluated in the enclosing "
"scope as they may depend on the values obtained from the leftmost iterable. "
"For example: ``(x*y for x in range(10) for y in range(x, x+10))``."
msgstr ""
"在生成器表达式中使用的变量会在为生成器对象调用 :meth:`~generator.__next__` "
"方法的时候以惰性方式被求值(即与普通生成器相同的方式)。 但是,最左侧 :keyword:`!for` "
"子句内的可迭代对象是会被立即求值的,因此它所造成的错误会在生成器表达式被定义时被检测到,而不是在获取第一个值时才出错。 后续的 "
":keyword:`!for` 子句以及最左侧 :keyword:`!for` "
"子句内的任何筛选条件无法在外层作用域内被求值,因为它们可能会依赖于从最左侧可迭代对象获取的值。 例如: ``(x*y for x in "
"range(10) for y in range(x, x+10))``."
#: ../../reference/expressions.rst:380
msgid ""
"The parentheses can be omitted on calls with only one argument. See section"
" :ref:`calls` for details."
msgstr "圆括号在只附带一个参数的调用中可以被省略。 详情参见 :ref:`calls` 一节。"
#: ../../reference/expressions.rst:383
msgid ""
"To avoid interfering with the expected operation of the generator expression"
" itself, ``yield`` and ``yield from`` expressions are prohibited in the "
"implicitly defined generator."
msgstr "为了避免干扰到生成器表达式本身的预期操作,禁止在隐式定义的生成器中使用 ``yield`` 和 ``yield from`` 表达式。"
#: ../../reference/expressions.rst:387
msgid ""
"If a generator expression contains either :keyword:`!async for` clauses or "
":keyword:`await` expressions it is called an :dfn:`asynchronous generator "
"expression`. An asynchronous generator expression returns a new "
"asynchronous generator object, which is an asynchronous iterator (see "
":ref:`async-iterators`)."
msgstr ""
"如果生成器表达式包含 :keyword:`!async for` 子句或 :keyword:`await` 表达式,则称为 "
":dfn:`异步生成器表达式`。 异步生成器表达式会返回一个新的异步生成器对象,此对象属于异步迭代器 (参见 :ref:`async-"
"iterators`)。"
#: ../../reference/expressions.rst:393
msgid "Asynchronous generator expressions were introduced."
msgstr "引入了异步生成器表达式。"
#: ../../reference/expressions.rst:396
msgid ""
"Prior to Python 3.7, asynchronous generator expressions could only appear in"
" :keyword:`async def` coroutines. Starting with 3.7, any function can use "
"asynchronous generator expressions."
msgstr ""
"在 Python 3.7 之前,异步生成器表达式只能在 :keyword:`async def` 协和中出现。 从 3.7 "
"开始,任何函数都可以使用异步生成器表达式。"
#: ../../reference/expressions.rst:408
msgid "Yield expressions"
msgstr "yield 表达式"
#: ../../reference/expressions.rst:420
msgid ""
"The yield expression is used when defining a :term:`generator` function or "
"an :term:`asynchronous generator` function and thus can only be used in the "
"body of a function definition. Using a yield expression in a function's "
"body causes that function to be a generator, and using it in an "
":keyword:`async def` function's body causes that coroutine function to be an"
" asynchronous generator. For example::"
msgstr ""
"yield 表达式在定义 :term:`generator` 函数或是 :term:`asynchronous generator` 的时候才会用到。 "
"因此只能在函数定义的内部使用yield表达式。 在一个函数体内使用 yield 表达式会使这个函数变成一个生成器,并且在一个 "
":keyword:`async def` 定义的函数体内使用 yield 表达式会让协程函数变成异步的生成器。 比如说::"
#: ../../reference/expressions.rst:433
msgid ""
"Due to their side effects on the containing scope, ``yield`` expressions are"
" not permitted as part of the implicitly defined scopes used to implement "
"comprehensions and generator expressions."
msgstr "由于它们会对外层作用域造成附带影响,``yield`` 表达式不被允许作为用于实现推导式和生成器表达式的隐式定义作用域的一部分。"
#: ../../reference/expressions.rst:437
msgid ""
"Yield expressions prohibited in the implicitly nested scopes used to "
"implement comprehensions and generator expressions."
msgstr "禁止在实现推导式和生成器表达式的隐式嵌套作用域中使用 yield 表达式。"
#: ../../reference/expressions.rst:441
msgid ""
"Generator functions are described below, while asynchronous generator "
"functions are described separately in section :ref:`asynchronous-generator-"
"functions`."
msgstr ""
"下面是对生成器函数的描述,异步生成器函数会在 :ref:`asynchronous-generator-functions` 一节中单独介绍。"
#: ../../reference/expressions.rst:445
msgid ""
"When a generator function is called, it returns an iterator known as a "
"generator. That generator then controls the execution of the generator "
"function. The execution starts when one of the generator's methods is "
"called. At that time, the execution proceeds to the first yield expression,"
" where it is suspended again, returning the value of "
":token:`expression_list` to the generator's caller. By suspended, we mean "
"that all local state is retained, including the current bindings of local "
"variables, the instruction pointer, the internal evaluation stack, and the "
"state of any exception handling. When the execution is resumed by calling "
"one of the generator's methods, the function can proceed exactly as if the "
"yield expression were just another external call. The value of the yield "
"expression after resuming depends on the method which resumed the execution."
" If :meth:`~generator.__next__` is used (typically via either a "
":keyword:`for` or the :func:`next` builtin) then the result is "
":const:`None`. Otherwise, if :meth:`~generator.send` is used, then the "
"result will be the value passed in to that method."
msgstr ""
"当一个生成器函数被调用的时候,它返回一个迭代器,称为生成器。然后这个生成器来控制生成器函数的执行。当这个生成器的某一个方法被调用的时候,生成器函数开始执行。这时会一直执行到第一个"
" yield 表达式,在此执行再次被挂起,给生成器的调用者返回 :token:`expression_list` "
"的值。挂起后,我们说所有局部状态都被保留下来,包括局部变量的当前绑定,指令指针,内部求值栈和任何异常处理的状态。通过调用生成器的某一个方法,生成器函数继续执行。此时函数的运行就和"
" yield 表达式只是一个外部函数调用的情况完全一致。恢复后 yield 表达式的值取决于调用的哪个方法来恢复执行。 如果用的是 "
":meth:`~generator.__next__` (通常通过语言内置的 :keyword:`for` 或是 :func:`next` 来调用) "
"那么结果就是 :const:`None`. 否则,如果用 :meth:`~generator.send`, 那么结果就是传递给send方法的值。"
#: ../../reference/expressions.rst:464
msgid ""
"All of this makes generator functions quite similar to coroutines; they "
"yield multiple times, they have more than one entry point and their "
"execution can be suspended. The only difference is that a generator "
"function cannot control where the execution should continue after it yields;"
" the control is always transferred to the generator's caller."
msgstr ""
"所有这些使生成器函数与协程非常相似;它们 yield 多次,它们具有多个入口点,并且它们的执行可以被挂起。唯一的区别是生成器函数不能控制在它在 "
"yield 后交给哪里继续执行;控制权总是转移到生成器的调用者。"
#: ../../reference/expressions.rst:470
msgid ""
"Yield expressions are allowed anywhere in a :keyword:`try` construct. If "
"the generator is not resumed before it is finalized (by reaching a zero "
"reference count or by being garbage collected), the generator-iterator's "
":meth:`~generator.close` method will be called, allowing any pending "
":keyword:`finally` clauses to execute."
msgstr ""
"在 :keyword:`try` "
"结构中的任何位置都允许yield表达式。如果生成器在(因为引用计数到零或是因为被垃圾回收)销毁之前没有恢复执行,将调用生成器-迭代器的 "
":meth:`~generator.close` 方法. close 方法允许任何挂起的 :keyword:`finally` 子句执行。"
#: ../../reference/expressions.rst:479
msgid ""
"When ``yield from <expr>`` is used, the supplied expression must be an "
"iterable. The values produced by iterating that iterable are passed directly"
" to the caller of the current generator's methods. Any values passed in with"
" :meth:`~generator.send` and any exceptions passed in with "
":meth:`~generator.throw` are passed to the underlying iterator if it has the"
" appropriate methods. If this is not the case, then :meth:`~generator.send`"
" will raise :exc:`AttributeError` or :exc:`TypeError`, while "
":meth:`~generator.throw` will just raise the passed in exception "
"immediately."
msgstr ""
"当使用 ``yield from <expr>`` 时,所提供的表达式必须是一个可迭代对象。 "
"迭代该可迭代对象所产生的值会被直接传递给当前生成器方法的调用者。 任何通过 :meth:`~generator.send` 传入的值以及任何通过 "
":meth:`~generator.throw` 传入的异常如果有适当的方法则会被传给下层迭代器。 如果不是这种情况,那么 "
":meth:`~generator.send` 将引发 :exc:`AttributeError` 或 :exc:`TypeError`,而 "
":meth:`~generator.throw` 将立即引发所转入的异常。"
#: ../../reference/expressions.rst:488
msgid ""
"When the underlying iterator is complete, the :attr:`~StopIteration.value` "
"attribute of the raised :exc:`StopIteration` instance becomes the value of "
"the yield expression. It can be either set explicitly when raising "
":exc:`StopIteration`, or automatically when the subiterator is a generator "
"(by returning a value from the subgenerator)."
msgstr ""
"当下层迭代器完成时,被引发的 :exc:`StopIteration` 实例的 :attr:`~StopIteration.value` 属性会成为 "
"yield 表达式的值。 它可以在引发 :exc:`StopIteration` "
"时被显式地设置,也可以在子迭代器是一个生成器时自动地设置(通过从子生成器返回一个值)。"
#: ../../reference/expressions.rst:494
msgid "Added ``yield from <expr>`` to delegate control flow to a subiterator."
msgstr "添加 ``yield from <expr>`` 以委托控制流给一个子迭代器。"
#: ../../reference/expressions.rst:497
msgid ""
"The parentheses may be omitted when the yield expression is the sole "
"expression on the right hand side of an assignment statement."
msgstr "当yield表达式是赋值语句右侧的唯一表达式时,括号可以省略。"
#: ../../reference/expressions.rst:503
msgid ":pep:`255` - Simple Generators"
msgstr ":pep:`255` - 简单生成器"
#: ../../reference/expressions.rst:503
msgid ""
"The proposal for adding generators and the :keyword:`yield` statement to "
"Python."
msgstr "在 Python 中加入生成器和 :keyword:`yield` 语句的提议。"
#: ../../reference/expressions.rst:507
msgid ":pep:`342` - Coroutines via Enhanced Generators"
msgstr ":pep:`342` - 通过增强型生成器实现协程"
#: ../../reference/expressions.rst:506
msgid ""
"The proposal to enhance the API and syntax of generators, making them usable"
" as simple coroutines."
msgstr "增强生成器 API 和语法的提议,使其可以被用作简单的协程。"
#: ../../reference/expressions.rst:511
msgid ":pep:`380` - Syntax for Delegating to a Subgenerator"
msgstr ":pep:`380` - 委托给子生成器的语法"
#: ../../reference/expressions.rst:510
msgid ""
"The proposal to introduce the :token:`yield_from` syntax, making delegation "
"to subgenerators easy."
msgstr "引入 :token:`yield_from` 语法以方便地委托给子生成器的提议。"
#: ../../reference/expressions.rst:514
msgid ":pep:`525` - Asynchronous Generators"
msgstr ":pep:`525` - 异步生成器"
#: ../../reference/expressions.rst:514
msgid ""
"The proposal that expanded on :pep:`492` by adding generator capabilities to"
" coroutine functions."
msgstr "通过给协程函数加入生成器功能对 :pep:`492` 进行扩展的提议。"
#: ../../reference/expressions.rst:521
msgid "Generator-iterator methods"
msgstr "生成器-迭代器的方法"
#: ../../reference/expressions.rst:523
msgid ""
"This subsection describes the methods of a generator iterator. They can be "
"used to control the execution of a generator function."
msgstr "这个子小节描述了生成器迭代器的方法。 它们可被用于控制生成器函数的执行。"
#: ../../reference/expressions.rst:526
msgid ""
"Note that calling any of the generator methods below when the generator is "
"already executing raises a :exc:`ValueError` exception."
msgstr "请注意在生成器已经在执行时调用以下任何方法都会引发 :exc:`ValueError` 异常。"
#: ../../reference/expressions.rst:534
msgid ""
"Starts the execution of a generator function or resumes it at the last "
"executed yield expression. When a generator function is resumed with a "
":meth:`~generator.__next__` method, the current yield expression always "
"evaluates to :const:`None`. The execution then continues to the next yield "
"expression, where the generator is suspended again, and the value of the "
":token:`expression_list` is returned to :meth:`__next__`'s caller. If the "
"generator exits without yielding another value, a :exc:`StopIteration` "
"exception is raised."
msgstr ""
"开始一个生成器函数的执行或是从上次执行的 yield 表达式位置恢复执行。 当一个生成器函数通过 :meth:`~generator.__next__`"
" 方法恢复执行时,当前的 yield 表达式总是取值为 :const:`None`。 随后会继续执行到下一个 yield 表达式,其 "
":token:`expression_list` 的值会返回给 :meth:`__next__` 的调用者。 如果生成器没有产生下一个值就退出,则将引发"
" :exc:`StopIteration` 异常。"
#: ../../reference/expressions.rst:543
msgid ""
"This method is normally called implicitly, e.g. by a :keyword:`for` loop, or"
" by the built-in :func:`next` function."
msgstr "此方法通常是隐式地调用,例如通过 :keyword:`for` 循环或是内置的 :func:`next` 函数。"
#: ../../reference/expressions.rst:549
msgid ""
"Resumes the execution and \"sends\" a value into the generator function. "
"The *value* argument becomes the result of the current yield expression. "
"The :meth:`send` method returns the next value yielded by the generator, or "
"raises :exc:`StopIteration` if the generator exits without yielding another "
"value. When :meth:`send` is called to start the generator, it must be "
"called with :const:`None` as the argument, because there is no yield "
"expression that could receive the value."
msgstr ""
"恢复执行并向生成器函数“发送”一个值。 *value* 参数将成为当前 yield 表达式的结果。 :meth:`send` "
"方法会返回生成器所产生的下一个值,或者如果生成器没有产生下一个值就退出则会引发 :exc:`StopIteration`。 当调用 "
":meth:`send` 来启动生成器时,它必须以 :const:`None` 作为调用参数,因为这时没有可以接收值的 yield 表达式。"
#: ../../reference/expressions.rst:560
msgid ""
"Raises an exception of type ``type`` at the point where the generator was "
"paused, and returns the next value yielded by the generator function. If "
"the generator exits without yielding another value, a :exc:`StopIteration` "
"exception is raised. If the generator function does not catch the passed-in"
" exception, or raises a different exception, then that exception propagates "
"to the caller."
msgstr ""
"在生成器暂停的位置引发 ``type`` 类型的异常,并返回该生成器函数所产生的下一个值。 如果生成器没有产生下一个值就退出,则将引发 "
":exc:`StopIteration` 异常。 如果生成器函数没有捕获传入的异常,或引发了另一个异常,则该异常会被传播给调用者。"
#: ../../reference/expressions.rst:571
msgid ""
"Raises a :exc:`GeneratorExit` at the point where the generator function was "
"paused. If the generator function then exits gracefully, is already closed,"
" or raises :exc:`GeneratorExit` (by not catching the exception), close "
"returns to its caller. If the generator yields a value, a "
":exc:`RuntimeError` is raised. If the generator raises any other exception,"
" it is propagated to the caller. :meth:`close` does nothing if the "
"generator has already exited due to an exception or normal exit."
msgstr ""
"在生成器函数暂停的位置引发 :exc:`GeneratorExit`。 如果生成器函数随后正常退出、已经关闭,或者引发了 "
":exc:`GeneratorExit` (由于未捕获异常),执行关闭将返回其调用方。 如果生成器产生了一个值,则将引发 "
":exc:`RuntimeError`。 如果生成器引发了任何其他异常,它将被传播给调用方。 如果生成器已经由于异常或以正常退出方式结束执行则 "
":meth:`close` 将不会做任何事。"
#: ../../reference/expressions.rst:582
msgid "Examples"
msgstr "例子"
#: ../../reference/expressions.rst:584
msgid ""
"Here is a simple example that demonstrates the behavior of generators and "
"generator functions::"
msgstr "这里是一个简单的例子,演示了生成器和生成器函数的行为::"
#: ../../reference/expressions.rst:611
msgid ""
"For examples using ``yield from``, see :ref:`pep-380` in \"What's New in "
"Python.\""
msgstr "对于 ``yield from`` 的例子, 参见“Python 有什么新变化”中的 :ref:`pep-380`。"
#: ../../reference/expressions.rst:617
msgid "Asynchronous generator functions"
msgstr "异步生成器函数"
#: ../../reference/expressions.rst:619
msgid ""
"The presence of a yield expression in a function or method defined using "
":keyword:`async def` further defines the function as an :term:`asynchronous "
"generator` function."
msgstr ""
"在一个使用 :keyword:`async def` 定义的函数或方法中出现的 yield 表达式会进一步将该函数定义为一个 "
":term:`asynchronous generator` 函数。"
#: ../../reference/expressions.rst:623
msgid ""
"When an asynchronous generator function is called, it returns an "
"asynchronous iterator known as an asynchronous generator object. That object"
" then controls the execution of the generator function. An asynchronous "
"generator object is typically used in an :keyword:`async for` statement in a"
" coroutine function analogously to how a generator object would be used in a"
" :keyword:`for` statement."
msgstr ""
"当一个异步生成器函数被调用时,它会返回一个名为异步生成器对象的异步迭代器。 此对象将在之后控制该生成器函数的执行。 异步生成器对象通常被用在协程函数的 "
":keyword:`async for` 语句中,类似于在 :keyword:`for` 语句中使用生成器对象。"
#: ../../reference/expressions.rst:630
msgid ""
"Calling one of the asynchronous generator's methods returns an "
":term:`awaitable` object, and the execution starts when this object is "
"awaited on. At that time, the execution proceeds to the first yield "
"expression, where it is suspended again, returning the value of "
":token:`expression_list` to the awaiting coroutine. As with a generator, "
"suspension means that all local state is retained, including the current "
"bindings of local variables, the instruction pointer, the internal "
"evaluation stack, and the state of any exception handling. When the "
"execution is resumed by awaiting on the next object returned by the "
"asynchronous generator's methods, the function can proceed exactly as if the"
" yield expression were just another external call. The value of the yield "
"expression after resuming depends on the method which resumed the execution."
" If :meth:`~agen.__anext__` is used then the result is :const:`None`. "
"Otherwise, if :meth:`~agen.asend` is used, then the result will be the value"
" passed in to that method."
msgstr ""
"调用异步生成器的方法之一将返回 :term:`awaitable` 对象,执行会在此对象被等待时启动。 到那时,执行将前往第一个 yield "
"表达式,在那里它会再次暂停,将 :token:`expression_list` 的值返回给等待中的协程。 "
"与生成器一样,挂起意味着局部的所有状态会被保留,包括局部变量的当前绑定、指令的指针、内部求值的堆栈以及任何异常处理的状态。 "
"当执行在等待异步生成器的方法返回下一个对象后恢复时,该函数可以从原状态继续进行,就仿佛 yield 表达式只是另一个外部调用。 恢复执行之后 yield"
" 表达式的值取决于恢复执行所用的方法。 如果使用 :meth:`~agen.__anext__` 则结果为 :const:`None`。 "
"否则的话,如果使用 :meth:`~agen.asend` 则结果将是传递给该方法的值。"
#: ../../reference/expressions.rst:646
msgid ""
"In an asynchronous generator function, yield expressions are allowed "
"anywhere in a :keyword:`try` construct. However, if an asynchronous "
"generator is not resumed before it is finalized (by reaching a zero "
"reference count or by being garbage collected), then a yield expression "
"within a :keyword:`!try` construct could result in a failure to execute "
"pending :keyword:`finally` clauses. In this case, it is the responsibility "
"of the event loop or scheduler running the asynchronous generator to call "
"the asynchronous generator-iterator's :meth:`~agen.aclose` method and run "
"the resulting coroutine object, thus allowing any pending "
":keyword:`!finally` clauses to execute."
msgstr ""
"在异步生成器函数中,yield 表达式允许出现在 :keyword:`try` "
"结构的任何位置。但是,如果一个异步生成器在其被终结(由于引用计数达到零或被作为垃圾回收)之前未被恢复,则 :keyword:`!try` 结构中的 "
"yield 表达式可能导致挂起的 :keyword:`finally` "
"子句执行失败。在此情况下,应由运行该异步生成器的事件循环或任务调度器来负责调用异步生成器-迭代器的 :meth:`~agen.aclose` "
"方法并运行所返回的协程对象,从而允许任何挂起的 :keyword:`!finally` 子句得以执行。"
#: ../../reference/expressions.rst:657
msgid ""
"To take care of finalization, an event loop should define a *finalizer* "
"function which takes an asynchronous generator-iterator and presumably calls"
" :meth:`~agen.aclose` and executes the coroutine. This *finalizer* may be "
"registered by calling :func:`sys.set_asyncgen_hooks`. When first iterated "
"over, an asynchronous generator-iterator will store the registered "
"*finalizer* to be called upon finalization. For a reference example of a "
"*finalizer* method see the implementation of "
"``asyncio.Loop.shutdown_asyncgens`` in :source:`Lib/asyncio/base_events.py`."
msgstr ""
"为了能处理最终化,事件循环应该定义一个 *终结器* 函数,它接受一个异步生成器-迭代器且可能调用 :meth:`~agen.aclose` 并执行协程。"
" 这个 *终结器* 可能通过调用 :func:`sys.set_asyncgen_hooks` 来注册。 当首次迭代时,异步生成器-"
"迭代器将保存已注册的 *终结器* 以便在最终化时调用。 有关For a reference example of a *终结器* 方法的参考示例请查看 "
":source:`Lib/asyncio/base_events.py` 中实现的 "
"``asyncio.Loop.shutdown_asyncgens``。"
#: ../../reference/expressions.rst:666
msgid ""
"The expression ``yield from <expr>`` is a syntax error when used in an "
"asynchronous generator function."
msgstr "``yield from <expr>`` 表达式如果在异步生成器函数中使用会引发语法错误。"
#: ../../reference/expressions.rst:673
msgid "Asynchronous generator-iterator methods"
msgstr "异步生成器-迭代器方法"
#: ../../reference/expressions.rst:675
msgid ""
"This subsection describes the methods of an asynchronous generator iterator,"
" which are used to control the execution of a generator function."
msgstr "这个子小节描述了异步生成器迭代器的方法,它们可被用于控制生成器函数的执行。"
#: ../../reference/expressions.rst:683
msgid ""
"Returns an awaitable which when run starts to execute the asynchronous "
"generator or resumes it at the last executed yield expression. When an "
"asynchronous generator function is resumed with an :meth:`~agen.__anext__` "
"method, the current yield expression always evaluates to :const:`None` in "
"the returned awaitable, which when run will continue to the next yield "
"expression. The value of the :token:`expression_list` of the yield "
"expression is the value of the :exc:`StopIteration` exception raised by the "
"completing coroutine. If the asynchronous generator exits without yielding "
"another value, the awaitable instead raises a :exc:`StopAsyncIteration` "
"exception, signalling that the asynchronous iteration has completed."
msgstr ""
"返回一个可等待对象,它在运行时会开始执行该异步生成器或是从上次执行的 yield 表达式位置恢复执行。 当一个异步生成器函数通过 "
":meth:`~agen.__anext__` 方法恢复执行时,当前的 yield 表达式所返回的可等待对象总是取值为 "
":const:`None`,它在运行时将继续执行到下一个 yield 表达式。 该 yield 表达式的 "
":token:`expression_list` 的值会是完成的协程所引发的 :exc:`StopIteration` 异常的值。 "
"如果异步生成器没有产生下一个值就退出,则该可等待对象将引发 :exc:`StopAsyncIteration` 异常,提示该异步迭代操作已完成。"
#: ../../reference/expressions.rst:695
msgid ""
"This method is normally called implicitly by a :keyword:`async for` loop."
msgstr "此方法通常是通过 :keyword:`async for` 循环隐式地调用。"
#: ../../reference/expressions.rst:700
msgid ""
"Returns an awaitable which when run resumes the execution of the "
"asynchronous generator. As with the :meth:`~generator.send()` method for a "
"generator, this \"sends\" a value into the asynchronous generator function, "
"and the *value* argument becomes the result of the current yield expression."
" The awaitable returned by the :meth:`asend` method will return the next "
"value yielded by the generator as the value of the raised "
":exc:`StopIteration`, or raises :exc:`StopAsyncIteration` if the "
"asynchronous generator exits without yielding another value. When "
":meth:`asend` is called to start the asynchronous generator, it must be "
"called with :const:`None` as the argument, because there is no yield "
"expression that could receive the value."
msgstr ""
"返回一个可等待对象,它在运行时会恢复该异步生成器的执行。 与生成器的 :meth:`~generator.send()` "
"方法一样,此方法会“发送”一个值给异步生成器函数,其 *value* 参数会成为当前 yield 表达式的结果值。 :meth:`asend` "
"方法所返回的可等待对象将返回生成器产生的下一个值,其值为所引发的 "
":exc:`StopIteration`,或者如果异步生成器没有产生下一个值就退出则引发 :exc:`StopAsyncIteration`。 当调用 "
":meth:`asend` 来启动异步生成器时,它必须以 :const:`None` 作为调用参数,因为这时没有可以接收值的 yield 表达式。"
#: ../../reference/expressions.rst:716
msgid ""
"Returns an awaitable that raises an exception of type ``type`` at the point "
"where the asynchronous generator was paused, and returns the next value "
"yielded by the generator function as the value of the raised "
":exc:`StopIteration` exception. If the asynchronous generator exits without"
" yielding another value, a :exc:`StopAsyncIteration` exception is raised by "
"the awaitable. If the generator function does not catch the passed-in "
"exception, or raises a different exception, then when the awaitable is run "
"that exception propagates to the caller of the awaitable."
msgstr ""
"返回一个可等待对象,它会在异步生成器暂停的位置引发 ``type`` 类型的异常,并返回该生成器函数所产生的下一个值,其值为所引发的 "
":exc:`StopIteration` 异常。 如果异步生成器没有产生下一个值就退出,则将由该可等待对象引发 "
":exc:`StopAsyncIteration` 异步。 "
"如果生成器函数没有捕获传入的异常,或引发了另一个异常,则当可等待对象运行时该异常会被传播给可等待对象的调用者。"
#: ../../reference/expressions.rst:731
msgid ""
"Returns an awaitable that when run will throw a :exc:`GeneratorExit` into "
"the asynchronous generator function at the point where it was paused. If the"
" asynchronous generator function then exits gracefully, is already closed, "
"or raises :exc:`GeneratorExit` (by not catching the exception), then the "
"returned awaitable will raise a :exc:`StopIteration` exception. Any further "
"awaitables returned by subsequent calls to the asynchronous generator will "
"raise a :exc:`StopAsyncIteration` exception. If the asynchronous generator "
"yields a value, a :exc:`RuntimeError` is raised by the awaitable. If the "
"asynchronous generator raises any other exception, it is propagated to the "
"caller of the awaitable. If the asynchronous generator has already exited "
"due to an exception or normal exit, then further calls to :meth:`aclose` "
"will return an awaitable that does nothing."
msgstr ""
"返回一个可等待对象,它会在运行时向异步生成器函数暂停的位置抛入一个 :exc:`GeneratorExit`。 如果该异步生成器函数正常退出、关闭或引发"
" :exc:`GeneratorExit` (由于未捕获该异常) 则返回的可等待对象将引发 :exc:`StopIteration` 异常。 "
"后续调用异步生成器所返回的任何其他可等待对象将引发 :exc:`StopAsyncIteration` 异常。 "
"如果异步生成器产生了一个值,该可等待对象会引发 :exc:`RuntimeError`。 "
"如果异步生成器引发任何其他异常,它会被传播给可等待对象的调用者。 如果异步生成器已经由于异常或正常退出则后续调用 :meth:`aclose` "
"将返回一个不会做任何事的可等待对象。"
#: ../../reference/expressions.rst:747
msgid "Primaries"
msgstr "原型"
#: ../../reference/expressions.rst:751
msgid ""
"Primaries represent the most tightly bound operations of the language. Their"
" syntax is:"
msgstr "原型代表编程语言中最紧密绑定的操作。 它们的句法如下:"
#: ../../reference/expressions.rst:761
msgid "Attribute references"
msgstr "属性引用"
#: ../../reference/expressions.rst:767
msgid "An attribute reference is a primary followed by a period and a name:"
msgstr "属性引用是后面带有一个句点加一个名称的原型:"
#: ../../reference/expressions.rst:777
msgid ""
"The primary must evaluate to an object of a type that supports attribute "
"references, which most objects do. This object is then asked to produce the"
" attribute whose name is the identifier. This production can be customized "
"by overriding the :meth:`__getattr__` method. If this attribute is not "
"available, the exception :exc:`AttributeError` is raised. Otherwise, the "
"type and value of the object produced is determined by the object. Multiple"
" evaluations of the same attribute reference may yield different objects."
msgstr ""
"此原型必须求值为一个支持属性引用的类型的对象,多数对象都支持属性引用。 随后该对象会被要求产生以指定标识符为名称的属性。 这个产生过程可通过重载 "
":meth:`__getattr__` 方法来自定义。 如果这个属性不可用,则将引发 :exc:`AttributeError` 异常。 "
"否则的话,所产生对象的类型和值会根据该对象来确定。 对同一属性引用的多次求值可能产生不同的对象。"
#: ../../reference/expressions.rst:789
msgid "Subscriptions"
msgstr "抽取"
#: ../../reference/expressions.rst:804
msgid ""
"A subscription selects an item of a sequence (string, tuple or list) or "
"mapping (dictionary) object:"
msgstr "抽取就是在序列(字符串、元组或列表)或映射(字典)对象中选择一项:"
#: ../../reference/expressions.rst:810
msgid ""
"The primary must evaluate to an object that supports subscription (lists or "
"dictionaries for example). User-defined objects can support subscription by"
" defining a :meth:`__getitem__` method."
msgstr ""
"此原型必须求值为一个支持抽取操作的对象(例如列表或字典)。 用户定义的对象可通过定义 :meth:`__getitem__` 方法来支持抽取操作。"
#: ../../reference/expressions.rst:814
msgid ""
"For built-in objects, there are two types of objects that support "
"subscription:"
msgstr "对于内置对象,有两种类型的对象支持抽取操作:"
#: ../../reference/expressions.rst:816
msgid ""