-
-
Notifications
You must be signed in to change notification settings - Fork 214
/
Copy pathenum.po
2793 lines (2466 loc) · 72.5 KB
/
enum.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
# Copyright (C) 2001-2022, Python Software Foundation
# This file is distributed under the same license as the Python package.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: Python 3.13\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-11-27 00:14+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-"
"tw)\n"
"Language: zh_TW\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
#: ../../howto/enum.rst:5
msgid "Enum HOWTO"
msgstr ""
#: ../../howto/enum.rst:11
msgid ""
"An :class:`Enum` is a set of symbolic names bound to unique values. They "
"are similar to global variables, but they offer a more useful :func:`repr`, "
"grouping, type-safety, and a few other features."
msgstr ""
#: ../../howto/enum.rst:15
msgid ""
"They are most useful when you have a variable that can take one of a limited "
"selection of values. For example, the days of the week::"
msgstr ""
#: ../../howto/enum.rst:18
msgid ""
">>> from enum import Enum\n"
">>> class Weekday(Enum):\n"
"... MONDAY = 1\n"
"... TUESDAY = 2\n"
"... WEDNESDAY = 3\n"
"... THURSDAY = 4\n"
"... FRIDAY = 5\n"
"... SATURDAY = 6\n"
"... SUNDAY = 7"
msgstr ""
#: ../../howto/enum.rst:28
msgid "Or perhaps the RGB primary colors::"
msgstr ""
#: ../../howto/enum.rst:30
msgid ""
">>> from enum import Enum\n"
">>> class Color(Enum):\n"
"... RED = 1\n"
"... GREEN = 2\n"
"... BLUE = 3"
msgstr ""
#: ../../howto/enum.rst:36
msgid ""
"As you can see, creating an :class:`Enum` is as simple as writing a class "
"that inherits from :class:`Enum` itself."
msgstr ""
#: ../../howto/enum.rst:39
msgid "Case of Enum Members"
msgstr ""
#: ../../howto/enum.rst:41
msgid ""
"Because Enums are used to represent constants, and to help avoid issues with "
"name clashes between mixin-class methods/attributes and enum names, we "
"strongly recommend using UPPER_CASE names for members, and will be using "
"that style in our examples."
msgstr ""
#: ../../howto/enum.rst:46
msgid ""
"Depending on the nature of the enum a member's value may or may not be "
"important, but either way that value can be used to get the corresponding "
"member::"
msgstr ""
#: ../../howto/enum.rst:50
msgid ""
">>> Weekday(3)\n"
"<Weekday.WEDNESDAY: 3>"
msgstr ""
">>> Weekday(3)\n"
"<Weekday.WEDNESDAY: 3>"
#: ../../howto/enum.rst:53
msgid ""
"As you can see, the ``repr()`` of a member shows the enum name, the member "
"name, and the value. The ``str()`` of a member shows only the enum name and "
"member name::"
msgstr ""
#: ../../howto/enum.rst:57
msgid ""
">>> print(Weekday.THURSDAY)\n"
"Weekday.THURSDAY"
msgstr ""
">>> print(Weekday.THURSDAY)\n"
"Weekday.THURSDAY"
#: ../../howto/enum.rst:60
msgid "The *type* of an enumeration member is the enum it belongs to::"
msgstr ""
#: ../../howto/enum.rst:62
msgid ""
">>> type(Weekday.MONDAY)\n"
"<enum 'Weekday'>\n"
">>> isinstance(Weekday.FRIDAY, Weekday)\n"
"True"
msgstr ""
">>> type(Weekday.MONDAY)\n"
"<enum 'Weekday'>\n"
">>> isinstance(Weekday.FRIDAY, Weekday)\n"
"True>>> type(Weekday.MONDAY)\n"
"<enum 'Weekday'>\n"
">>> isinstance(Weekday.FRIDAY, Weekday)\n"
"True"
#: ../../howto/enum.rst:67
msgid "Enum members have an attribute that contains just their :attr:`!name`::"
msgstr ""
#: ../../howto/enum.rst:69
msgid ""
">>> print(Weekday.TUESDAY.name)\n"
"TUESDAY"
msgstr ""
">>> print(Weekday.TUESDAY.name)\n"
"TUESDAY"
#: ../../howto/enum.rst:72
msgid "Likewise, they have an attribute for their :attr:`!value`::"
msgstr ""
#: ../../howto/enum.rst:75
msgid ""
">>> Weekday.WEDNESDAY.value\n"
"3"
msgstr ""
">>> Weekday.WEDNESDAY.value\n"
"3"
#: ../../howto/enum.rst:78
msgid ""
"Unlike many languages that treat enumerations solely as name/value pairs, "
"Python Enums can have behavior added. For example, :class:`datetime.date` "
"has two methods for returning the weekday: :meth:`~datetime.date.weekday` "
"and :meth:`~datetime.date.isoweekday`. The difference is that one of them "
"counts from 0-6 and the other from 1-7. Rather than keep track of that "
"ourselves we can add a method to the :class:`!Weekday` enum to extract the "
"day from the :class:`~datetime.date` instance and return the matching enum "
"member::"
msgstr ""
#: ../../howto/enum.rst:87
msgid ""
"@classmethod\n"
"def from_date(cls, date):\n"
" return cls(date.isoweekday())"
msgstr ""
"@classmethod\n"
"def from_date(cls, date):\n"
" return cls(date.isoweekday())"
#: ../../howto/enum.rst:91
msgid "The complete :class:`!Weekday` enum now looks like this::"
msgstr ""
#: ../../howto/enum.rst:93
msgid ""
">>> class Weekday(Enum):\n"
"... MONDAY = 1\n"
"... TUESDAY = 2\n"
"... WEDNESDAY = 3\n"
"... THURSDAY = 4\n"
"... FRIDAY = 5\n"
"... SATURDAY = 6\n"
"... SUNDAY = 7\n"
"... #\n"
"... @classmethod\n"
"... def from_date(cls, date):\n"
"... return cls(date.isoweekday())"
msgstr ""
">>> class Weekday(Enum):\n"
"... MONDAY = 1\n"
"... TUESDAY = 2\n"
"... WEDNESDAY = 3\n"
"... THURSDAY = 4\n"
"... FRIDAY = 5\n"
"... SATURDAY = 6\n"
"... SUNDAY = 7\n"
"... #\n"
"... @classmethod\n"
"... def from_date(cls, date):\n"
"... return cls(date.isoweekday())"
#: ../../howto/enum.rst:106
msgid "Now we can find out what today is! Observe::"
msgstr ""
#: ../../howto/enum.rst:108
msgid ""
">>> from datetime import date\n"
">>> Weekday.from_date(date.today()) \n"
"<Weekday.TUESDAY: 2>"
msgstr ""
#: ../../howto/enum.rst:112
msgid ""
"Of course, if you're reading this on some other day, you'll see that day "
"instead."
msgstr ""
#: ../../howto/enum.rst:114
msgid ""
"This :class:`!Weekday` enum is great if our variable only needs one day, but "
"what if we need several? Maybe we're writing a function to plot chores "
"during a week, and don't want to use a :class:`list` -- we could use a "
"different type of :class:`Enum`::"
msgstr ""
#: ../../howto/enum.rst:119
msgid ""
">>> from enum import Flag\n"
">>> class Weekday(Flag):\n"
"... MONDAY = 1\n"
"... TUESDAY = 2\n"
"... WEDNESDAY = 4\n"
"... THURSDAY = 8\n"
"... FRIDAY = 16\n"
"... SATURDAY = 32\n"
"... SUNDAY = 64"
msgstr ""
">>> from enum import Flag\n"
">>> class Weekday(Flag):\n"
"... MONDAY = 1\n"
"... TUESDAY = 2\n"
"... WEDNESDAY = 4\n"
"... THURSDAY = 8\n"
"... FRIDAY = 16\n"
"... SATURDAY = 32\n"
"... SUNDAY = 64"
#: ../../howto/enum.rst:129
msgid ""
"We've changed two things: we're inherited from :class:`Flag`, and the values "
"are all powers of 2."
msgstr ""
#: ../../howto/enum.rst:132
msgid ""
"Just like the original :class:`!Weekday` enum above, we can have a single "
"selection::"
msgstr ""
#: ../../howto/enum.rst:134
msgid ""
">>> first_week_day = Weekday.MONDAY\n"
">>> first_week_day\n"
"<Weekday.MONDAY: 1>"
msgstr ""
">>> first_week_day = Weekday.MONDAY\n"
">>> first_week_day\n"
"<Weekday.MONDAY: 1>"
#: ../../howto/enum.rst:138
msgid ""
"But :class:`Flag` also allows us to combine several members into a single "
"variable::"
msgstr ""
#: ../../howto/enum.rst:141
msgid ""
">>> weekend = Weekday.SATURDAY | Weekday.SUNDAY\n"
">>> weekend\n"
"<Weekday.SATURDAY|SUNDAY: 96>"
msgstr ""
">>> weekend = Weekday.SATURDAY | Weekday.SUNDAY\n"
">>> weekend\n"
"<Weekday.SATURDAY|SUNDAY: 96>"
#: ../../howto/enum.rst:145
msgid "You can even iterate over a :class:`Flag` variable::"
msgstr ""
#: ../../howto/enum.rst:147
msgid ""
">>> for day in weekend:\n"
"... print(day)\n"
"Weekday.SATURDAY\n"
"Weekday.SUNDAY"
msgstr ""
">>> for day in weekend:\n"
"... print(day)\n"
"Weekday.SATURDAY\n"
"Weekday.SUNDAY"
#: ../../howto/enum.rst:152
msgid "Okay, let's get some chores set up::"
msgstr ""
#: ../../howto/enum.rst:154
msgid ""
">>> chores_for_ethan = {\n"
"... 'feed the cat': Weekday.MONDAY | Weekday.WEDNESDAY | Weekday."
"FRIDAY,\n"
"... 'do the dishes': Weekday.TUESDAY | Weekday.THURSDAY,\n"
"... 'answer SO questions': Weekday.SATURDAY,\n"
"... }"
msgstr ""
">>> chores_for_ethan = {\n"
"... 'feed the cat': Weekday.MONDAY | Weekday.WEDNESDAY | Weekday."
"FRIDAY,\n"
"... 'do the dishes': Weekday.TUESDAY | Weekday.THURSDAY,\n"
"... 'answer SO questions': Weekday.SATURDAY,\n"
"... }"
#: ../../howto/enum.rst:160
msgid "And a function to display the chores for a given day::"
msgstr ""
#: ../../howto/enum.rst:162
msgid ""
">>> def show_chores(chores, day):\n"
"... for chore, days in chores.items():\n"
"... if day in days:\n"
"... print(chore)\n"
"...\n"
">>> show_chores(chores_for_ethan, Weekday.SATURDAY)\n"
"answer SO questions"
msgstr ""
">>> def show_chores(chores, day):\n"
"... for chore, days in chores.items():\n"
"... if day in days:\n"
"... print(chore)\n"
"...\n"
">>> show_chores(chores_for_ethan, Weekday.SATURDAY)\n"
"answer SO questions"
#: ../../howto/enum.rst:170
msgid ""
"In cases where the actual values of the members do not matter, you can save "
"yourself some work and use :func:`auto` for the values::"
msgstr ""
#: ../../howto/enum.rst:173
msgid ""
">>> from enum import auto\n"
">>> class Weekday(Flag):\n"
"... MONDAY = auto()\n"
"... TUESDAY = auto()\n"
"... WEDNESDAY = auto()\n"
"... THURSDAY = auto()\n"
"... FRIDAY = auto()\n"
"... SATURDAY = auto()\n"
"... SUNDAY = auto()\n"
"... WEEKEND = SATURDAY | SUNDAY"
msgstr ""
">>> from enum import auto\n"
">>> class Weekday(Flag):\n"
"... MONDAY = auto()\n"
"... TUESDAY = auto()\n"
"... WEDNESDAY = auto()\n"
"... THURSDAY = auto()\n"
"... FRIDAY = auto()\n"
"... SATURDAY = auto()\n"
"... SUNDAY = auto()\n"
"... WEEKEND = SATURDAY | SUNDAY"
#: ../../howto/enum.rst:189
msgid "Programmatic access to enumeration members and their attributes"
msgstr ""
#: ../../howto/enum.rst:191
msgid ""
"Sometimes it's useful to access members in enumerations programmatically (i."
"e. situations where ``Color.RED`` won't do because the exact color is not "
"known at program-writing time). ``Enum`` allows such access::"
msgstr ""
#: ../../howto/enum.rst:195
msgid ""
">>> Color(1)\n"
"<Color.RED: 1>\n"
">>> Color(3)\n"
"<Color.BLUE: 3>"
msgstr ""
">>> Color(1)\n"
"<Color.RED: 1>\n"
">>> Color(3)\n"
"<Color.BLUE: 3>"
#: ../../howto/enum.rst:200
msgid "If you want to access enum members by *name*, use item access::"
msgstr ""
#: ../../howto/enum.rst:202
msgid ""
">>> Color['RED']\n"
"<Color.RED: 1>\n"
">>> Color['GREEN']\n"
"<Color.GREEN: 2>"
msgstr ""
">>> Color['RED']\n"
"<Color.RED: 1>\n"
">>> Color['GREEN']\n"
"<Color.GREEN: 2>"
#: ../../howto/enum.rst:207
msgid ""
"If you have an enum member and need its :attr:`!name` or :attr:`!value`::"
msgstr ""
#: ../../howto/enum.rst:209
msgid ""
">>> member = Color.RED\n"
">>> member.name\n"
"'RED'\n"
">>> member.value\n"
"1"
msgstr ""
">>> member = Color.RED\n"
">>> member.name\n"
"'RED'\n"
">>> member.value\n"
"1"
#: ../../howto/enum.rst:217
msgid "Duplicating enum members and values"
msgstr ""
#: ../../howto/enum.rst:219
msgid "Having two enum members with the same name is invalid::"
msgstr ""
#: ../../howto/enum.rst:221
msgid ""
">>> class Shape(Enum):\n"
"... SQUARE = 2\n"
"... SQUARE = 3\n"
"...\n"
"Traceback (most recent call last):\n"
"...\n"
"TypeError: 'SQUARE' already defined as 2"
msgstr ""
">>> class Shape(Enum):\n"
"... SQUARE = 2\n"
"... SQUARE = 3\n"
"...\n"
"Traceback (most recent call last):\n"
"...\n"
"TypeError: 'SQUARE' already defined as 2"
#: ../../howto/enum.rst:229
msgid ""
"However, an enum member can have other names associated with it. Given two "
"entries ``A`` and ``B`` with the same value (and ``A`` defined first), ``B`` "
"is an alias for the member ``A``. By-value lookup of the value of ``A`` "
"will return the member ``A``. By-name lookup of ``A`` will return the "
"member ``A``. By-name lookup of ``B`` will also return the member ``A``::"
msgstr ""
#: ../../howto/enum.rst:235
msgid ""
">>> class Shape(Enum):\n"
"... SQUARE = 2\n"
"... DIAMOND = 1\n"
"... CIRCLE = 3\n"
"... ALIAS_FOR_SQUARE = 2\n"
"...\n"
">>> Shape.SQUARE\n"
"<Shape.SQUARE: 2>\n"
">>> Shape.ALIAS_FOR_SQUARE\n"
"<Shape.SQUARE: 2>\n"
">>> Shape(2)\n"
"<Shape.SQUARE: 2>"
msgstr ""
">>> class Shape(Enum):\n"
"... SQUARE = 2\n"
"... DIAMOND = 1\n"
"... CIRCLE = 3\n"
"... ALIAS_FOR_SQUARE = 2\n"
"...\n"
">>> Shape.SQUARE\n"
"<Shape.SQUARE: 2>\n"
">>> Shape.ALIAS_FOR_SQUARE\n"
"<Shape.SQUARE: 2>\n"
">>> Shape(2)\n"
"<Shape.SQUARE: 2>"
#: ../../howto/enum.rst:250
msgid ""
"Attempting to create a member with the same name as an already defined "
"attribute (another member, a method, etc.) or attempting to create an "
"attribute with the same name as a member is not allowed."
msgstr ""
#: ../../howto/enum.rst:256
msgid "Ensuring unique enumeration values"
msgstr ""
#: ../../howto/enum.rst:258
msgid ""
"By default, enumerations allow multiple names as aliases for the same value. "
"When this behavior isn't desired, you can use the :func:`unique` decorator::"
msgstr ""
#: ../../howto/enum.rst:261
msgid ""
">>> from enum import Enum, unique\n"
">>> @unique\n"
"... class Mistake(Enum):\n"
"... ONE = 1\n"
"... TWO = 2\n"
"... THREE = 3\n"
"... FOUR = 3\n"
"...\n"
"Traceback (most recent call last):\n"
"...\n"
"ValueError: duplicate values found in <enum 'Mistake'>: FOUR -> THREE"
msgstr ""
">>> from enum import Enum, unique\n"
">>> @unique\n"
"... class Mistake(Enum):\n"
"... ONE = 1\n"
"... TWO = 2\n"
"... THREE = 3\n"
"... FOUR = 3\n"
"...\n"
"Traceback (most recent call last):\n"
"...\n"
"ValueError: duplicate values found in <enum 'Mistake'>: FOUR -> THREE"
#: ../../howto/enum.rst:275
msgid "Using automatic values"
msgstr ""
#: ../../howto/enum.rst:277
msgid "If the exact value is unimportant you can use :class:`auto`::"
msgstr ""
#: ../../howto/enum.rst:279
msgid ""
">>> from enum import Enum, auto\n"
">>> class Color(Enum):\n"
"... RED = auto()\n"
"... BLUE = auto()\n"
"... GREEN = auto()\n"
"...\n"
">>> [member.value for member in Color]\n"
"[1, 2, 3]"
msgstr ""
">>> from enum import Enum, auto\n"
">>> class Color(Enum):\n"
"... RED = auto()\n"
"... BLUE = auto()\n"
"... GREEN = auto()\n"
"...\n"
">>> [member.value for member in Color]\n"
"[1, 2, 3]"
#: ../../howto/enum.rst:288
msgid ""
"The values are chosen by :func:`~Enum._generate_next_value_`, which can be "
"overridden::"
msgstr ""
#: ../../howto/enum.rst:291
msgid ""
">>> class AutoName(Enum):\n"
"... @staticmethod\n"
"... def _generate_next_value_(name, start, count, last_values):\n"
"... return name\n"
"...\n"
">>> class Ordinal(AutoName):\n"
"... NORTH = auto()\n"
"... SOUTH = auto()\n"
"... EAST = auto()\n"
"... WEST = auto()\n"
"...\n"
">>> [member.value for member in Ordinal]\n"
"['NORTH', 'SOUTH', 'EAST', 'WEST']"
msgstr ""
">>> class AutoName(Enum):\n"
"... @staticmethod\n"
"... def _generate_next_value_(name, start, count, last_values):\n"
"... return name\n"
"...\n"
">>> class Ordinal(AutoName):\n"
"... NORTH = auto()\n"
"... SOUTH = auto()\n"
"... EAST = auto()\n"
"... WEST = auto()\n"
"...\n"
">>> [member.value for member in Ordinal]\n"
"['NORTH', 'SOUTH', 'EAST', 'WEST']"
#: ../../howto/enum.rst:307
msgid ""
"The :meth:`~Enum._generate_next_value_` method must be defined before any "
"members."
msgstr ""
#: ../../howto/enum.rst:310
msgid "Iteration"
msgstr ""
#: ../../howto/enum.rst:312
msgid "Iterating over the members of an enum does not provide the aliases::"
msgstr ""
#: ../../howto/enum.rst:314
msgid ""
">>> list(Shape)\n"
"[<Shape.SQUARE: 2>, <Shape.DIAMOND: 1>, <Shape.CIRCLE: 3>]\n"
">>> list(Weekday)\n"
"[<Weekday.MONDAY: 1>, <Weekday.TUESDAY: 2>, <Weekday.WEDNESDAY: 4>, <Weekday."
"THURSDAY: 8>, <Weekday.FRIDAY: 16>, <Weekday.SATURDAY: 32>, <Weekday.SUNDAY: "
"64>]"
msgstr ""
">>> list(Shape)\n"
"[<Shape.SQUARE: 2>, <Shape.DIAMOND: 1>, <Shape.CIRCLE: 3>]\n"
">>> list(Weekday)\n"
"[<Weekday.MONDAY: 1>, <Weekday.TUESDAY: 2>, <Weekday.WEDNESDAY: 4>, <Weekday."
"THURSDAY: 8>, <Weekday.FRIDAY: 16>, <Weekday.SATURDAY: 32>, <Weekday.SUNDAY: "
"64>]"
#: ../../howto/enum.rst:319
msgid ""
"Note that the aliases ``Shape.ALIAS_FOR_SQUARE`` and ``Weekday.WEEKEND`` "
"aren't shown."
msgstr ""
#: ../../howto/enum.rst:321
msgid ""
"The special attribute ``__members__`` is a read-only ordered mapping of "
"names to members. It includes all names defined in the enumeration, "
"including the aliases::"
msgstr ""
#: ../../howto/enum.rst:325
msgid ""
">>> for name, member in Shape.__members__.items():\n"
"... name, member\n"
"...\n"
"('SQUARE', <Shape.SQUARE: 2>)\n"
"('DIAMOND', <Shape.DIAMOND: 1>)\n"
"('CIRCLE', <Shape.CIRCLE: 3>)\n"
"('ALIAS_FOR_SQUARE', <Shape.SQUARE: 2>)"
msgstr ""
">>> for name, member in Shape.__members__.items():\n"
"... name, member\n"
"...\n"
"('SQUARE', <Shape.SQUARE: 2>)\n"
"('DIAMOND', <Shape.DIAMOND: 1>)\n"
"('CIRCLE', <Shape.CIRCLE: 3>)\n"
"('ALIAS_FOR_SQUARE', <Shape.SQUARE: 2>)"
#: ../../howto/enum.rst:333
msgid ""
"The ``__members__`` attribute can be used for detailed programmatic access "
"to the enumeration members. For example, finding all the aliases::"
msgstr ""
#: ../../howto/enum.rst:336
msgid ""
">>> [name for name, member in Shape.__members__.items() if member.name != "
"name]\n"
"['ALIAS_FOR_SQUARE']"
msgstr ""
">>> [name for name, member in Shape.__members__.items() if member.name != "
"name]\n"
"['ALIAS_FOR_SQUARE']"
#: ../../howto/enum.rst:341
msgid ""
"Aliases for flags include values with multiple flags set, such as ``3``, and "
"no flags set, i.e. ``0``."
msgstr ""
#: ../../howto/enum.rst:346
msgid "Comparisons"
msgstr "比較"
#: ../../howto/enum.rst:348
msgid "Enumeration members are compared by identity::"
msgstr ""
#: ../../howto/enum.rst:350
msgid ""
">>> Color.RED is Color.RED\n"
"True\n"
">>> Color.RED is Color.BLUE\n"
"False\n"
">>> Color.RED is not Color.BLUE\n"
"True"
msgstr ""
">>> Color.RED is Color.RED\n"
"True\n"
">>> Color.RED is Color.BLUE\n"
"False\n"
">>> Color.RED is not Color.BLUE\n"
"True"
#: ../../howto/enum.rst:357
msgid ""
"Ordered comparisons between enumeration values are *not* supported. Enum "
"members are not integers (but see `IntEnum`_ below)::"
msgstr ""
#: ../../howto/enum.rst:360
msgid ""
">>> Color.RED < Color.BLUE\n"
"Traceback (most recent call last):\n"
" File \"<stdin>\", line 1, in <module>\n"
"TypeError: '<' not supported between instances of 'Color' and 'Color'"
msgstr ""
">>> Color.RED < Color.BLUE\n"
"Traceback (most recent call last):\n"
" File \"<stdin>\", line 1, in <module>\n"
"TypeError: '<' not supported between instances of 'Color' and 'Color'"
#: ../../howto/enum.rst:365
msgid "Equality comparisons are defined though::"
msgstr ""
#: ../../howto/enum.rst:367
msgid ""
">>> Color.BLUE == Color.RED\n"
"False\n"
">>> Color.BLUE != Color.RED\n"
"True\n"
">>> Color.BLUE == Color.BLUE\n"
"True"
msgstr ""
">>> Color.BLUE == Color.RED\n"
"False\n"
">>> Color.BLUE != Color.RED\n"
"True\n"
">>> Color.BLUE == Color.BLUE\n"
"True"
#: ../../howto/enum.rst:374
msgid ""
"Comparisons against non-enumeration values will always compare not equal "
"(again, :class:`IntEnum` was explicitly designed to behave differently, see "
"below)::"
msgstr ""
#: ../../howto/enum.rst:378
msgid ""
">>> Color.BLUE == 2\n"
"False"
msgstr ""
">>> Color.BLUE == 2\n"
"False"
#: ../../howto/enum.rst:383
msgid ""
"It is possible to reload modules -- if a reloaded module contains enums, "
"they will be recreated, and the new members may not compare identical/equal "
"to the original members."
msgstr ""
#: ../../howto/enum.rst:388
msgid "Allowed members and attributes of enumerations"
msgstr ""
#: ../../howto/enum.rst:390
msgid ""
"Most of the examples above use integers for enumeration values. Using "
"integers is short and handy (and provided by default by the `Functional "
"API`_), but not strictly enforced. In the vast majority of use-cases, one "
"doesn't care what the actual value of an enumeration is. But if the value "
"*is* important, enumerations can have arbitrary values."
msgstr ""
#: ../../howto/enum.rst:396
msgid ""
"Enumerations are Python classes, and can have methods and special methods as "
"usual. If we have this enumeration::"
msgstr ""
#: ../../howto/enum.rst:399
msgid ""
">>> class Mood(Enum):\n"
"... FUNKY = 1\n"
"... HAPPY = 3\n"
"...\n"
"... def describe(self):\n"
"... # self is the member here\n"
"... return self.name, self.value\n"
"...\n"
"... def __str__(self):\n"
"... return 'my custom str! {0}'.format(self.value)\n"
"...\n"
"... @classmethod\n"
"... def favorite_mood(cls):\n"
"... # cls here is the enumeration\n"
"... return cls.HAPPY\n"
"..."
msgstr ""
#: ../../howto/enum.rst:416
msgid "Then::"
msgstr "然後: ::"
#: ../../howto/enum.rst:418
msgid ""
">>> Mood.favorite_mood()\n"
"<Mood.HAPPY: 3>\n"
">>> Mood.HAPPY.describe()\n"
"('HAPPY', 3)\n"
">>> str(Mood.FUNKY)\n"
"'my custom str! 1'"
msgstr ""
">>> Mood.favorite_mood()\n"
"<Mood.HAPPY: 3>\n"
">>> Mood.HAPPY.describe()\n"
"('HAPPY', 3)\n"
">>> str(Mood.FUNKY)\n"
"'my custom str! 1'"
#: ../../howto/enum.rst:425
msgid ""
"The rules for what is allowed are as follows: names that start and end with "
"a single underscore are reserved by enum and cannot be used; all other "
"attributes defined within an enumeration will become members of this "
"enumeration, with the exception of special methods (:meth:`~object."
"__str__`, :meth:`~object.__add__`, etc.), descriptors (methods are also "
"descriptors), and variable names listed in :attr:`~Enum._ignore_`."
msgstr ""
#: ../../howto/enum.rst:432
msgid ""
"Note: if your enumeration defines :meth:`~object.__new__` and/or :meth:"
"`~object.__init__`, any value(s) given to the enum member will be passed "
"into those methods. See `Planet`_ for an example."
msgstr ""
#: ../../howto/enum.rst:438
msgid ""
"The :meth:`~object.__new__` method, if defined, is used during creation of "
"the Enum members; it is then replaced by Enum's :meth:`~object.__new__` "
"which is used after class creation for lookup of existing members. See :ref:"
"`new-vs-init` for more details."
msgstr ""
#: ../../howto/enum.rst:445
msgid "Restricted Enum subclassing"
msgstr ""
#: ../../howto/enum.rst:447
msgid ""
"A new :class:`Enum` class must have one base enum class, up to one concrete "
"data type, and as many :class:`object`-based mixin classes as needed. The "
"order of these base classes is::"
msgstr ""
#: ../../howto/enum.rst:451
msgid ""
"class EnumName([mix-in, ...,] [data-type,] base-enum):\n"
" pass"
msgstr ""
"class EnumName([mix-in, ...,] [data-type,] base-enum):\n"
" pass"
#: ../../howto/enum.rst:454
msgid ""
"Also, subclassing an enumeration is allowed only if the enumeration does not "
"define any members. So this is forbidden::"
msgstr ""
#: ../../howto/enum.rst:457
msgid ""
">>> class MoreColor(Color):\n"
"... PINK = 17\n"
"...\n"
"Traceback (most recent call last):\n"
"...\n"
"TypeError: <enum 'MoreColor'> cannot extend <enum 'Color'>"
msgstr ""
">>> class MoreColor(Color):\n"
"... PINK = 17\n"
"...\n"
"Traceback (most recent call last):\n"
"...\n"
"TypeError: <enum 'MoreColor'> cannot extend <enum 'Color'>"
#: ../../howto/enum.rst:464
msgid "But this is allowed::"
msgstr "但這是允許的:"
#: ../../howto/enum.rst:466
msgid ""
">>> class Foo(Enum):\n"
"... def some_behavior(self):\n"
"... pass\n"
"...\n"
">>> class Bar(Foo):\n"
"... HAPPY = 1\n"
"... SAD = 2\n"
"..."
msgstr ""
">>> class Foo(Enum):\n"
"... def some_behavior(self):\n"
"... pass\n"
"...\n"
">>> class Bar(Foo):\n"
"... HAPPY = 1\n"
"... SAD = 2\n"
"..."
#: ../../howto/enum.rst:475
msgid ""
"Allowing subclassing of enums that define members would lead to a violation "
"of some important invariants of types and instances. On the other hand, it "
"makes sense to allow sharing some common behavior between a group of "
"enumerations. (See `OrderedEnum`_ for an example.)"
msgstr ""
#: ../../howto/enum.rst:484
msgid "Dataclass support"
msgstr ""
#: ../../howto/enum.rst:486
msgid ""
"When inheriting from a :class:`~dataclasses.dataclass`, the :meth:`~Enum."
"__repr__` omits the inherited class' name. For example::"
msgstr ""
#: ../../howto/enum.rst:489
msgid ""
">>> from dataclasses import dataclass, field\n"
">>> @dataclass\n"
"... class CreatureDataMixin:\n"
"... size: str\n"
"... legs: int\n"
"... tail: bool = field(repr=False, default=True)\n"
"...\n"
">>> class Creature(CreatureDataMixin, Enum):\n"
"... BEETLE = 'small', 6\n"
"... DOG = 'medium', 4\n"
"...\n"
">>> Creature.DOG\n"
"<Creature.DOG: size='medium', legs=4>"
msgstr ""
">>> from dataclasses import dataclass, field\n"
">>> @dataclass\n"
"... class CreatureDataMixin:\n"
"... size: str\n"
"... legs: int\n"
"... tail: bool = field(repr=False, default=True)\n"
"...\n"
">>> class Creature(CreatureDataMixin, Enum):\n"
"... BEETLE = 'small', 6\n"
"... DOG = 'medium', 4\n"
"...\n"
">>> Creature.DOG\n"
"<Creature.DOG: size='medium', legs=4>"
#: ../../howto/enum.rst:503
msgid ""
"Use the :func:`~dataclasses.dataclass` argument ``repr=False`` to use the "
"standard :func:`repr`."
msgstr ""
#: ../../howto/enum.rst:506
msgid ""
"Only the dataclass fields are shown in the value area, not the dataclass' "
"name."
msgstr ""
#: ../../howto/enum.rst:512
msgid ""
"Adding :func:`~dataclasses.dataclass` decorator to :class:`Enum` and its "
"subclasses is not supported. It will not raise any errors, but it will "
"produce very strange results at runtime, such as members being equal to each "
"other::"
msgstr ""
#: ../../howto/enum.rst:517
msgid ""
">>> @dataclass # don't do this: it does not make any sense\n"
"... class Color(Enum):\n"
"... RED = 1\n"
"... BLUE = 2\n"
"...\n"
">>> Color.RED is Color.BLUE\n"
"False\n"