-
-
Notifications
You must be signed in to change notification settings - Fork 224
Expand file tree
/
Copy pathclasses.po
More file actions
1865 lines (1716 loc) · 80.3 KB
/
classes.po
File metadata and controls
1865 lines (1716 loc) · 80.3 KB
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 Python Software Foundation
# This file is distributed under the same license as the Python package.
#
# Translators:
# josix, 2018
# Steven Hsu <hsuhaochun@gmail.com>, 2021
msgid ""
msgstr ""
"Project-Id-Version: Python 3.14\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2026-02-18 00:20+0000\n"
"PO-Revision-Date: 2022-12-26 23:12+0800\n"
"Last-Translator: Adrian Liaw <adrianliaw2000@gmail.com>\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"
"Plural-Forms: nplurals=1; plural=0;\n"
"X-Generator: Poedit 3.2.2\n"
"X-Poedit-Bookmarks: 0,26,52,77,102,-1,-1,-1,-1,-1\n"
#: ../../tutorial/classes.rst:5
msgid "Classes"
msgstr "Class(類別)"
#: ../../tutorial/classes.rst:7
msgid ""
"Classes provide a means of bundling data and functionality together. "
"Creating a new class creates a new *type* of object, allowing new "
"*instances* of that type to be made. Each class instance can have "
"attributes attached to it for maintaining its state. Class instances can "
"also have methods (defined by its class) for modifying its state."
msgstr ""
"Class 提供了一種結合資料與功能的手段。建立一個 class 將會新增一個物件的\\ *型"
"別 (type)*,並且允許建立該型別的新\\ *實例 (instance)*。每一個 class 實例可以"
"擁有一些維持該實例狀態的屬性 (attribute)。Class 實例也可以有一些(由其 class "
"所定義的)method(方法),用於修改該實例的狀態。"
#: ../../tutorial/classes.rst:13
msgid ""
"Compared with other programming languages, Python's class mechanism adds "
"classes with a minimum of new syntax and semantics. It is a mixture of the "
"class mechanisms found in C++ and Modula-3. Python classes provide all the "
"standard features of Object Oriented Programming: the class inheritance "
"mechanism allows multiple base classes, a derived class can override any "
"methods of its base class or classes, and a method can call the method of a "
"base class with the same name. Objects can contain arbitrary amounts and "
"kinds of data. As is true for modules, classes partake of the dynamic "
"nature of Python: they are created at runtime, and can be modified further "
"after creation."
msgstr ""
"與其他程式語言相比,Python 的 class 機制為 class 增加了最少的新語法跟語意。他"
"混合了 C++ 和 Modula-3 的 class 機制。Python 的 class 提供了所有物件導向程式"
"設計 (Object Oriented Programming) 的標準特色:class 繼承機制允許多個 base "
"class(基底類別),一個 derived class(衍生類別)可以覆寫 (override) 其 base "
"class 的任何 method,且一個 method 可以用相同的名稱呼叫其 base class 的 "
"method。物件可以包含任意數量及任意種類的資料。如同模組一樣,class 也具有 "
"Python 的動態特性:他們在執行期 (runtime) 被建立,且可以在建立之後被修改。"
#: ../../tutorial/classes.rst:23
msgid ""
"In C++ terminology, normally class members (including the data members) are "
"*public* (except see below :ref:`tut-private`), and all member functions are "
"*virtual*. As in Modula-3, there are no shorthands for referencing the "
"object's members from its methods: the method function is declared with an "
"explicit first argument representing the object, which is provided "
"implicitly by the call. As in Smalltalk, classes themselves are objects. "
"This provides semantics for importing and renaming. Unlike C++ and "
"Modula-3, built-in types can be used as base classes for extension by the "
"user. Also, like in C++, most built-in operators with special syntax "
"(arithmetic operators, subscripting etc.) can be redefined for class "
"instances."
msgstr ""
"在 C++ 的術語中,class 成員(包含資料成員)通常都是\\ *公開*\\ 的(除了以下內"
"容::ref:`tut-private`\\ ),而所有的成員函式都是\\ *虛擬*\\ 的。如同在 "
"Modula-3 中一樣,Python 並沒有提供簡寫可以從物件的 method 裡參照其成員:"
"method 函式與一個外顯的 (explicit)、第一個代表物件的引數被宣告,而此引數是在"
"呼叫時隱性地 (implicitly) 被提供。如同在 Smalltak 中,class 都是物件,這為 "
"import 及重新命名提供了語意。不像 C++ 和 Modula-3,Pyhon 內建的型別可以被使用"
"者以 base class 用於其他擴充 (extension)。另外,如同在 C++ 中,大多數有著特別"
"語法的內建運算子(算術運算子、下標等)都可以為了 class 實例而被重新定義。"
#: ../../tutorial/classes.rst:34
msgid ""
"(Lacking universally accepted terminology to talk about classes, I will make "
"occasional use of Smalltalk and C++ terms. I would use Modula-3 terms, "
"since its object-oriented semantics are closer to those of Python than C++, "
"but I expect that few readers have heard of it.)"
msgstr ""
"(由於缺乏普遍能接受的術語來討論 class,我偶爾會使用 Smalltalk 和 C++ 的術"
"語。我會使用 Modula-3 的術語,因為它比 C++ 更接近 Python 的物件導向語意,但我"
"預期比較少的讀者會聽過它。)"
#: ../../tutorial/classes.rst:43
msgid "A Word About Names and Objects"
msgstr "關於名稱與物件的一段話"
#: ../../tutorial/classes.rst:45
msgid ""
"Objects have individuality, and multiple names (in multiple scopes) can be "
"bound to the same object. This is known as aliasing in other languages. "
"This is usually not appreciated on a first glance at Python, and can be "
"safely ignored when dealing with immutable basic types (numbers, strings, "
"tuples). However, aliasing has a possibly surprising effect on the "
"semantics of Python code involving mutable objects such as lists, "
"dictionaries, and most other types. This is usually used to the benefit of "
"the program, since aliases behave like pointers in some respects. For "
"example, passing an object is cheap since only a pointer is passed by the "
"implementation; and if a function modifies an object passed as an argument, "
"the caller will see the change --- this eliminates the need for two "
"different argument passing mechanisms as in Pascal."
msgstr ""
"物件有個體性 (individuality),且多個名稱(在多個作用域 (scope) )可以被連結到"
"相同的物件。這在其他語言中被稱為別名 (aliasing)。初次接觸 Python 時通常不會注"
"意這件事,而在處理不可變的基本型別(數值、字串、tuple)時,它也可以安全地被忽"
"略。然而,別名在含有可變物件(如 list(串列)、dictionary(字典)、和大多數其"
"他的型別)的 Python 程式碼語意中,可能會有意外的效果。這通常有利於程式,因為"
"別名在某些方面表現得像指標 (pointer)。舉例來說,在實作時傳遞一個物件是便宜"
"的,因為只有指標被傳遞;假如函式修改了一個作為引數傳遞的物件,呼叫函式者 "
"(caller) 能夠見到這些改變——這消除了在 Pascal 中兩個相異引數傳遞機制的需求。"
#: ../../tutorial/classes.rst:61
msgid "Python Scopes and Namespaces"
msgstr "Python 作用域 (Scope) 及命名空間 (Namespace)"
#: ../../tutorial/classes.rst:63
msgid ""
"Before introducing classes, I first have to tell you something about "
"Python's scope rules. Class definitions play some neat tricks with "
"namespaces, and you need to know how scopes and namespaces work to fully "
"understand what's going on. Incidentally, knowledge about this subject is "
"useful for any advanced Python programmer."
msgstr ""
"在介紹 class 之前,我必須先告訴你一些關於 Python 作用域的規則。Class "
"definition(類別定義)以命名空間展現了一些俐落的技巧,而你需要了解作用域和命"
"名空間的運作才能完整理解正在發生的事情。順帶一提,關於這個主題的知識對任何進"
"階的 Python 程式設計師都是很有用的。"
#: ../../tutorial/classes.rst:69
msgid "Let's begin with some definitions."
msgstr "讓我們從一些定義開始。"
#: ../../tutorial/classes.rst:71
msgid ""
"A *namespace* is a mapping from names to objects. Most namespaces are "
"currently implemented as Python dictionaries, but that's normally not "
"noticeable in any way (except for performance), and it may change in the "
"future. Examples of namespaces are: the set of built-in names (containing "
"functions such as :func:`abs`, and built-in exception names); the global "
"names in a module; and the local names in a function invocation. In a sense "
"the set of attributes of an object also form a namespace. The important "
"thing to know about namespaces is that there is absolutely no relation "
"between names in different namespaces; for instance, two different modules "
"may both define a function ``maximize`` without confusion --- users of the "
"modules must prefix it with the module name."
msgstr ""
"*命名空間*\\ 是從名稱到物件的對映。大部分的命名空間現在都是以 Python 的 "
"dictionary 被實作,但通常不會以任何方式被察覺(除了性能),且它可能會在未來改"
"變。命名空間的例子有:內建名稱的集合(包含如 :func:`abs` 的函式,和內建的例外"
"名稱);模組中的全域 (global) 名稱;和在函式呼叫中的區域 (local) 名稱。某種意"
"義上,物件中的屬性集合也會形成一個命名空間。關於命名空間的重要一點是,不同命"
"名空間中的名稱之間絕對沒有關係;舉例來說,兩個不一樣的模組都可以定義一個 "
"``maximize`` 函式而不會混淆——模組的使用者必須為它加上前綴 (prefix) 模組名稱。"
#: ../../tutorial/classes.rst:82
msgid ""
"By the way, I use the word *attribute* for any name following a dot --- for "
"example, in the expression ``z.real``, ``real`` is an attribute of the "
"object ``z``. Strictly speaking, references to names in modules are "
"attribute references: in the expression ``modname.funcname``, ``modname`` is "
"a module object and ``funcname`` is an attribute of it. In this case there "
"happens to be a straightforward mapping between the module's attributes and "
"the global names defined in the module: they share the same namespace! [#]_"
msgstr ""
"順帶一提,我使用\\ *屬性 (attribute)* 這個字,統稱句號 (dot) 後面的任何名稱——"
"例如,運算式中的 ``z.real``,``real`` 是物件 ``z`` 的一個屬性。嚴格來說,模組"
"中名稱的參照都是屬性參照:在運算式 ``modname.funcname`` 中,``modname`` 是模"
"組物件而 ``funcname`` 是它的屬性。在這種情況下,模組的屬性和模組中定義的全域"
"名稱碰巧有一個直接的對映:他們共享了相同的命名空間![#]_"
#: ../../tutorial/classes.rst:90
msgid ""
"Attributes may be read-only or writable. In the latter case, assignment to "
"attributes is possible. Module attributes are writable: you can write "
"``modname.the_answer = 42``. Writable attributes may also be deleted with "
"the :keyword:`del` statement. For example, ``del modname.the_answer`` will "
"remove the attribute :attr:`!the_answer` from the object named by "
"``modname``."
msgstr ""
"屬性可以是唯讀的或可寫的。在後者的情況下,對屬性的賦值是可能的。模組屬性是可"
"寫的:你可以寫 ``modname.the_answer = 42``。可寫屬性也可以用 :keyword:`del` "
"陳述式刪除。例如,``del modname.the_answer`` 將從名為 ``modname`` 的物件中刪"
"除屬性 :attr:`!the_answer`。"
#: ../../tutorial/classes.rst:96
msgid ""
"Namespaces are created at different moments and have different lifetimes. "
"The namespace containing the built-in names is created when the Python "
"interpreter starts up, and is never deleted. The global namespace for a "
"module is created when the module definition is read in; normally, module "
"namespaces also last until the interpreter quits. The statements executed "
"by the top-level invocation of the interpreter, either read from a script "
"file or interactively, are considered part of a module called :mod:"
"`__main__`, so they have their own global namespace. (The built-in names "
"actually also live in a module; this is called :mod:`builtins`.)"
msgstr ""
"命名空間在不同的時刻被建立,並且有不同的壽命。當 Python 直譯器啟動時,含有內"
"建名稱的命名空間會被建立,並且永遠不會被刪除。當模組定義被讀入時,模組的全域"
"命名空間會被建立;一般情況下,模組的命名空間也會持續到直譯器結束。被直譯器的"
"頂層呼叫 (top-level invocation) 執行的陳述式,不論是從腳本檔案讀取的或是互動"
"模式中的,會被視為一個稱為 :mod:`__main__` 的模組的一部分,因此它們具有自己的"
"全域命名空間。(內建名稱實際上也存在一個模組中,它被稱為 :mod:`builtins`。)"
#: ../../tutorial/classes.rst:106
msgid ""
"The local namespace for a function is created when the function is called, "
"and deleted when the function returns or raises an exception that is not "
"handled within the function. (Actually, forgetting would be a better way to "
"describe what actually happens.) Of course, recursive invocations each have "
"their own local namespace."
msgstr ""
"函式的區域命名空間是在呼叫函式時建立的,而當函式回傳,或引發了未在函式中處理"
"的例外時,此命名空間將會被刪除。(實際上,忘記是描述實際發生的事情的更好方"
"法。) 當然,每個遞迴呼叫 (recursive invocation) 都有自己的區域命名空間。"
#: ../../tutorial/classes.rst:112
msgid ""
"A *scope* is a textual region of a Python program where a namespace is "
"directly accessible. \"Directly accessible\" here means that an unqualified "
"reference to a name attempts to find the name in the namespace."
msgstr ""
"*作用域*\\ 是 Python 程式中的一個文本區域 (textual region),在此區域,命名空"
"間是可直接存取的。這裡的「可直接存取的」意思是,對一個名稱的非限定參照 "
"(unqualified reference) 可以在命名空間內嘗試尋找該名稱。"
#: ../../tutorial/classes.rst:116
msgid ""
"Although scopes are determined statically, they are used dynamically. At any "
"time during execution, there are 3 or 4 nested scopes whose namespaces are "
"directly accessible:"
msgstr ""
"儘管作用域是靜態地被決定,但它們是動態地被使用的。在執行期間內的任何時間點,"
"都會有 3 或 4 個巢狀的作用域,其命名空間是可以被直接存取的:"
#: ../../tutorial/classes.rst:120
msgid "the innermost scope, which is searched first, contains the local names"
msgstr "最內層作用域,會最先被搜尋,而它包含了區域名稱"
#: ../../tutorial/classes.rst:121
msgid ""
"the scopes of any enclosing functions, which are searched starting with the "
"nearest enclosing scope, contain non-local, but also non-global names"
msgstr ""
"任何外圍函式 (enclosing function) 的作用域,會從最近的外圍作用域開始搜尋,它"
"包含了非區域 (non-local) 和非全域 (non-global) 的名稱"
#: ../../tutorial/classes.rst:123
msgid "the next-to-last scope contains the current module's global names"
msgstr "倒數第二個作用域,包含目前模組的全域名稱"
#: ../../tutorial/classes.rst:124
msgid ""
"the outermost scope (searched last) is the namespace containing built-in "
"names"
msgstr "最外面的作用域(最後搜尋),是包含內建名稱的命名空間"
#: ../../tutorial/classes.rst:126
msgid ""
"If a name is declared global, then all references and assignments go "
"directly to the next-to-last scope containing the module's global names. To "
"rebind variables found outside of the innermost scope, the :keyword:"
"`nonlocal` statement can be used; if not declared nonlocal, those variables "
"are read-only (an attempt to write to such a variable will simply create a "
"*new* local variable in the innermost scope, leaving the identically named "
"outer variable unchanged)."
msgstr ""
"如果一個名稱被宣告為全域,則所有的參照和賦值將直接轉到包含模組全域名稱的倒數"
"第二個作用域。要重新連結最內層作用域以外找到的變數,可以使用 :keyword:"
"`nonlocal` 陳述式;如果那些變數沒有被宣告為 nonlocal,則它們會是唯讀的(嘗試"
"寫入這樣的變數只會在最內層的作用域內建立一個\\ *新的*\\ 區域變數,同名的外部"
"變數則維持不變)。"
#: ../../tutorial/classes.rst:133
msgid ""
"Usually, the local scope references the local names of the (textually) "
"current function. Outside functions, the local scope references the same "
"namespace as the global scope: the module's namespace. Class definitions "
"place yet another namespace in the local scope."
msgstr ""
"通常,區域作用域會參照(文本的)目前函式的區域名稱。在函式外部,區域作用域與"
"全域作用域參照相同的命名空間:模組的命名空間。然而,Class definition 會在區域"
"作用域中放置另一個命名空間。"
#: ../../tutorial/classes.rst:138
msgid ""
"It is important to realize that scopes are determined textually: the global "
"scope of a function defined in a module is that module's namespace, no "
"matter from where or by what alias the function is called. On the other "
"hand, the actual search for names is done dynamically, at run time --- "
"however, the language definition is evolving towards static name resolution, "
"at \"compile\" time, so don't rely on dynamic name resolution! (In fact, "
"local variables are already determined statically.)"
msgstr ""
"務必要了解,作用域是按文本被決定的:在模組中定義的函式,其全域作用域便是該模"
"組的命名空間,無論函式是從何處或以什麼別名被呼叫。另一方面,對名稱的實際搜尋"
"是在執行時期 (run time) 動態完成的——但是,語言定義的發展,正朝向在「編譯」時"
"期 (compile time) 的靜態名稱解析 (static name resolution),所以不要太依賴動態"
"名稱解析 (dynamic name resolution)! (事實上,局部變數已經是靜態地被決定。)"
#: ../../tutorial/classes.rst:146
msgid ""
"A special quirk of Python is that -- if no :keyword:`global` or :keyword:"
"`nonlocal` statement is in effect -- assignments to names always go into the "
"innermost scope. Assignments do not copy data --- they just bind names to "
"objects. The same is true for deletions: the statement ``del x`` removes "
"the binding of ``x`` from the namespace referenced by the local scope. In "
"fact, all operations that introduce new names use the local scope: in "
"particular, :keyword:`import` statements and function definitions bind the "
"module or function name in the local scope."
msgstr ""
"一個 Python 的特殊癖好是——假如沒有 :keyword:`global` 或 :keyword:`nonlocal` "
"陳述式的效果——名稱的賦值 (assignment) 都會指向最內層作用域。賦值不會複製資料"
"——它們只會把名稱連結至物件。刪除也是一樣:陳述式 ``del x`` 會從區域作用域參照"
"的命名空間移除 ``x`` 的連結。事實上,引入新名稱的所有運算都使用區域作用域:特"
"別是 :keyword:`import` 陳述式和函式定義,會連結區域作用域內的模組或函式名稱。"
#: ../../tutorial/classes.rst:154
msgid ""
"The :keyword:`global` statement can be used to indicate that particular "
"variables live in the global scope and should be rebound there; the :keyword:"
"`nonlocal` statement indicates that particular variables live in an "
"enclosing scope and should be rebound there."
msgstr ""
":keyword:`global` 陳述式可以用來表示特定變數存活在全域作用域,應該被重新綁定"
"到那裡;:keyword:`nonlocal` 陳述式表示特定變數存活在外圍作用域內,應該被重新"
"綁定到那裡。"
#: ../../tutorial/classes.rst:162
msgid "Scopes and Namespaces Example"
msgstr "作用域和命名空間的範例"
#: ../../tutorial/classes.rst:164
msgid ""
"This is an example demonstrating how to reference the different scopes and "
"namespaces, and how :keyword:`global` and :keyword:`nonlocal` affect "
"variable binding::"
msgstr ""
"這是一個範例,演示如何參照不同的作用域和命名空間,以及 :keyword:`global` 和 :"
"keyword:`nonlocal` 如何影響變數的綁定: ::"
#: ../../tutorial/classes.rst:168
msgid ""
"def scope_test():\n"
" def do_local():\n"
" spam = \"local spam\"\n"
"\n"
" def do_nonlocal():\n"
" nonlocal spam\n"
" spam = \"nonlocal spam\"\n"
"\n"
" def do_global():\n"
" global spam\n"
" spam = \"global spam\"\n"
"\n"
" spam = \"test spam\"\n"
" do_local()\n"
" print(\"After local assignment:\", spam)\n"
" do_nonlocal()\n"
" print(\"After nonlocal assignment:\", spam)\n"
" do_global()\n"
" print(\"After global assignment:\", spam)\n"
"\n"
"scope_test()\n"
"print(\"In global scope:\", spam)"
msgstr ""
"def scope_test():\n"
" def do_local():\n"
" spam = \"local spam\"\n"
"\n"
" def do_nonlocal():\n"
" nonlocal spam\n"
" spam = \"nonlocal spam\"\n"
"\n"
" def do_global():\n"
" global spam\n"
" spam = \"global spam\"\n"
"\n"
" spam = \"test spam\"\n"
" do_local()\n"
" print(\"After local assignment:\", spam)\n"
" do_nonlocal()\n"
" print(\"After nonlocal assignment:\", spam)\n"
" do_global()\n"
" print(\"After global assignment:\", spam)\n"
"\n"
"scope_test()\n"
"print(\"In global scope:\", spam)"
#: ../../tutorial/classes.rst:191
msgid "The output of the example code is:"
msgstr "範例程式碼的輸出是:"
#: ../../tutorial/classes.rst:193
msgid ""
"After local assignment: test spam\n"
"After nonlocal assignment: nonlocal spam\n"
"After global assignment: nonlocal spam\n"
"In global scope: global spam"
msgstr ""
"After local assignment: test spam\n"
"After nonlocal assignment: nonlocal spam\n"
"After global assignment: nonlocal spam\n"
"In global scope: global spam"
#: ../../tutorial/classes.rst:200
msgid ""
"Note how the *local* assignment (which is default) didn't change "
"*scope_test*\\'s binding of *spam*. The :keyword:`nonlocal` assignment "
"changed *scope_test*\\'s binding of *spam*, and the :keyword:`global` "
"assignment changed the module-level binding."
msgstr ""
"請注意,*區域*\\ 賦值(預設情況)不會改變 *scope_test* 對 *spam* 的連結。:"
"keyword:`nonlocal` 賦值改變了 *scope_test* 對 *spam* 的連結,而 :keyword:"
"`global` 賦值改變了模組層次的連結。"
#: ../../tutorial/classes.rst:205
msgid ""
"You can also see that there was no previous binding for *spam* before the :"
"keyword:`global` assignment."
msgstr "你還可以發現,在 :keyword:`global` 賦值之前,沒有對 *spam* 的連結。"
#: ../../tutorial/classes.rst:212
msgid "A First Look at Classes"
msgstr "初見 class"
#: ../../tutorial/classes.rst:214
msgid ""
"Classes introduce a little bit of new syntax, three new object types, and "
"some new semantics."
msgstr "Class 採用一些新的語法,三個新的物件型別,以及一些新的語意。"
#: ../../tutorial/classes.rst:221
msgid "Class Definition Syntax"
msgstr "Class definition(類別定義)語法"
#: ../../tutorial/classes.rst:223
msgid "The simplest form of class definition looks like this::"
msgstr "Class definition 最簡單的形式如下: ::"
#: ../../tutorial/classes.rst:225
msgid ""
"class ClassName:\n"
" <statement-1>\n"
" .\n"
" .\n"
" .\n"
" <statement-N>"
msgstr ""
"class ClassName:\n"
" <statement-1>\n"
" .\n"
" .\n"
" .\n"
" <statement-N>"
#: ../../tutorial/classes.rst:232
msgid ""
"Class definitions, like function definitions (:keyword:`def` statements) "
"must be executed before they have any effect. (You could conceivably place "
"a class definition in a branch of an :keyword:`if` statement, or inside a "
"function.)"
msgstr ""
"Class definition,如同函式定義(\\ :keyword:`def` 陳述式),必須在它們有任何"
"效果前先執行。(你可以想像把 class definition 放在一個 :keyword:`if` 陳述式的"
"分支,或在函式裡。)"
#: ../../tutorial/classes.rst:236
msgid ""
"In practice, the statements inside a class definition will usually be "
"function definitions, but other statements are allowed, and sometimes useful "
"--- we'll come back to this later. The function definitions inside a class "
"normally have a peculiar form of argument list, dictated by the calling "
"conventions for methods --- again, this is explained later."
msgstr ""
"在實作時,class definition 內的陳述式通常會是函式定義,但其他陳述式也是允許"
"的,有時很有用——我們稍後會回到這裡。Class 中的函式定義通常會有一個獨特的引數"
"列表形式,取決於 method 的呼叫慣例——再一次地,這將會在稍後解釋。"
#: ../../tutorial/classes.rst:242
msgid ""
"When a class definition is entered, a new namespace is created, and used as "
"the local scope --- thus, all assignments to local variables go into this "
"new namespace. In particular, function definitions bind the name of the new "
"function here."
msgstr ""
"當進入 class definition,一個新的命名空間將會被建立,並且作為區域作用域——因"
"此,所有區域變數的賦值將進入這個新的命名空間。特別是,函式定義會在這裡連結新"
"函式的名稱。"
#: ../../tutorial/classes.rst:247
msgid ""
"When a class definition is left normally (via the end), a *class object* is "
"created. This is basically a wrapper around the contents of the namespace "
"created by the class definition; we'll learn more about class objects in the "
"next section. The original local scope (the one in effect just before the "
"class definition was entered) is reinstated, and the class object is bound "
"here to the class name given in the class definition header (:class:`!"
"ClassName` in the example)."
msgstr ""
"正常地(從結尾處)離開 class definition 時,一個 *class 物件*\\ 會被建立。基"
"本上這是一個包裝器 (wrapper),裝著 class definition 建立的命名空間內容;我們"
"將在下一節中更加了解 class 物件。原始的區域作用域(在進入 class definition 之"
"前已生效的作用域)會恢復,在此 class 物件會被連結到 class definition 標頭中給"
"出的 class 名稱(在範例中為 :class:`!ClassName`\\ )。"
#: ../../tutorial/classes.rst:259
msgid "Class Objects"
msgstr "Class 物件"
#: ../../tutorial/classes.rst:261
msgid ""
"Class objects support two kinds of operations: attribute references and "
"instantiation."
msgstr ""
"Class 物件支援兩種運算:屬性參照 (attribute reference) 和實例化 "
"(instantiation)。"
#: ../../tutorial/classes.rst:264
msgid ""
"*Attribute references* use the standard syntax used for all attribute "
"references in Python: ``obj.name``. Valid attribute names are all the names "
"that were in the class's namespace when the class object was created. So, "
"if the class definition looked like this::"
msgstr ""
"*屬性參照*\\ 使用 Python 中所有屬性參照的標準語法:``obj.name``。有效的屬性名"
"稱是 class 物件被建立時,class 的命名空間中所有的名稱。所以,如果 class "
"definition 看起來像這樣: ::"
#: ../../tutorial/classes.rst:269
msgid ""
"class MyClass:\n"
" \"\"\"A simple example class\"\"\"\n"
" i = 12345\n"
"\n"
" def f(self):\n"
" return 'hello world'"
msgstr ""
"class MyClass:\n"
" \"\"\"一個簡單的類別範例\"\"\"\n"
" i = 12345\n"
"\n"
" def f(self):\n"
" return 'hello world'"
#: ../../tutorial/classes.rst:276
msgid ""
"then ``MyClass.i`` and ``MyClass.f`` are valid attribute references, "
"returning an integer and a function object, respectively. Class attributes "
"can also be assigned to, so you can change the value of ``MyClass.i`` by "
"assignment. :attr:`~type.__doc__` is also a valid attribute, returning the "
"docstring belonging to the class: ``\"A simple example class\"``."
msgstr ""
"那麼 ``MyClass.i`` 和 ``MyClass.f`` 都是有效的屬性參照,會分別回傳一個整數和"
"一個函式物件。Class 屬性也可以被指派 (assign),所以你可以透過賦值改變 "
"``MyClass.i`` 的值。:attr:`~type.__doc__` 也是一個有效的屬性,會回傳屬於該 "
"class 的說明字串 (docstring):``\"A simple example class\"``。"
#: ../../tutorial/classes.rst:282
msgid ""
"Class *instantiation* uses function notation. Just pretend that the class "
"object is a parameterless function that returns a new instance of the class. "
"For example (assuming the above class)::"
msgstr ""
"Class *實例化*\\ 使用了函式記法 (function notation)。就好像 class 物件是一個"
"沒有參數的函式,它回傳一個新的 class 實例。例如(假設是上述的 class): ::"
#: ../../tutorial/classes.rst:286 ../../tutorial/classes.rst:303
msgid "x = MyClass()"
msgstr "x = MyClass()"
#: ../../tutorial/classes.rst:288
msgid ""
"creates a new *instance* of the class and assigns this object to the local "
"variable ``x``."
msgstr "建立 class 的一個新\\ *實例*,並將此物件指派給區域變數 ``x``。"
#: ../../tutorial/classes.rst:291
msgid ""
"The instantiation operation (\"calling\" a class object) creates an empty "
"object. Many classes like to create objects with instances customized to a "
"specific initial state. Therefore a class may define a special method named :"
"meth:`~object.__init__`, like this::"
msgstr ""
"實例化運算(「呼叫」一個 class 物件)會建立一個空的物件。許多 class 喜歡在建"
"立物件時有著自訂的特定實例初始狀態。因此,class 可以定義一個名為 :meth:"
"`~object.__init__` 的特別 method,像這樣: ::"
#: ../../tutorial/classes.rst:296
msgid ""
"def __init__(self):\n"
" self.data = []"
msgstr ""
"def __init__(self):\n"
" self.data = []"
#: ../../tutorial/classes.rst:299
msgid ""
"When a class defines an :meth:`~object.__init__` method, class instantiation "
"automatically invokes :meth:`!__init__` for the newly created class "
"instance. So in this example, a new, initialized instance can be obtained "
"by::"
msgstr ""
"當 class 定義了 :meth:`~object.__init__` method,class 實例化會為新建的 "
"class 實例自動叫用 :meth:`!__init__`。所以在這個範例中,一個新的、初始化的實"
"例可以如此獲得: ::"
#: ../../tutorial/classes.rst:305
msgid ""
"Of course, the :meth:`~object.__init__` method may have arguments for "
"greater flexibility. In that case, arguments given to the class "
"instantiation operator are passed on to :meth:`!__init__`. For example, ::"
msgstr ""
"當然,:meth:`~object.__init__` method 可能為了更多的彈性而有引數。在這種情況"
"下,要給 class 實例化運算子的引數會被傳遞給 :meth:`!__init__`。例如: ::"
#: ../../tutorial/classes.rst:309
msgid ""
">>> class Complex:\n"
"... def __init__(self, realpart, imagpart):\n"
"... self.r = realpart\n"
"... self.i = imagpart\n"
"...\n"
">>> x = Complex(3.0, -4.5)\n"
">>> x.r, x.i\n"
"(3.0, -4.5)"
msgstr ""
">>> class Complex:\n"
"... def __init__(self, realpart, imagpart):\n"
"... self.r = realpart\n"
"... self.i = imagpart\n"
"...\n"
">>> x = Complex(3.0, -4.5)\n"
">>> x.r, x.i\n"
"(3.0, -4.5)"
#: ../../tutorial/classes.rst:322
msgid "Instance Objects"
msgstr "實例物件"
#: ../../tutorial/classes.rst:324
msgid ""
"Now what can we do with instance objects? The only operations understood by "
"instance objects are attribute references. There are two kinds of valid "
"attribute names: data attributes and methods."
msgstr ""
"現在,我們可以如何處理實例物件?實例物件能理解的唯一運算就是屬性參照。有兩種"
"有效的屬性名稱:資料屬性 (data attribute) 和 method。"
#: ../../tutorial/classes.rst:328
msgid ""
"*Data attributes* correspond to \"instance variables\" in Smalltalk, and to "
"\"data members\" in C++. Data attributes need not be declared; like local "
"variables, they spring into existence when they are first assigned to. For "
"example, if ``x`` is the instance of :class:`!MyClass` created above, the "
"following piece of code will print the value ``16``, without leaving a "
"trace::"
msgstr ""
"*資料屬性*\\ 對應 Smalltalk 中的「實例變數」,以及 C++ 中的「資料成員」。資料"
"屬性不需要被宣告;和區域變數一樣,它們在第一次被賦值時就會立即存在。例如,如"
"果 ``x`` 是 :class:`!MyClass` 在上述例子中建立的實例,下面的程式碼將印出值 "
"``16``,而不留下蹤跡: ::"
#: ../../tutorial/classes.rst:334
msgid ""
"x.counter = 1\n"
"while x.counter < 10:\n"
" x.counter = x.counter * 2\n"
"print(x.counter)\n"
"del x.counter"
msgstr ""
"x.counter = 1\n"
"while x.counter < 10:\n"
" x.counter = x.counter * 2\n"
"print(x.counter)\n"
"del x.counter"
#: ../../tutorial/classes.rst:340
msgid ""
"The other kind of instance attribute reference is a *method*. A method is a "
"function that \"belongs to\" an object."
msgstr ""
"另一種執行個體屬性參考是 *方法* (method)。方法是\"屬於\"一個物件的函式。"
#: ../../tutorial/classes.rst:345
msgid ""
"Valid method names of an instance object depend on its class. By "
"definition, all attributes of a class that are function objects define "
"corresponding methods of its instances. So in our example, ``x.f`` is a "
"valid method reference, since ``MyClass.f`` is a function, but ``x.i`` is "
"not, since ``MyClass.i`` is not. But ``x.f`` is not the same thing as "
"``MyClass.f`` --- it is a *method object*, not a function object."
msgstr ""
"實例物件的有效 method 名稱取決於其 class。根據定義,一個 class 中所有的函式物"
"件屬性,就定義了實例的對應 method。所以在我們的例子中,``x.f`` 是一個有效的 "
"method 參照,因為 ``MyClass.f`` 是一個函式,但 ``x.i`` 不是,因為 ``MyClass."
"i`` 不是。但 ``x.f`` 與 ``MyClass.f`` 是不一樣的——它是一個 *method 物件*,而"
"不是函式物件。"
#: ../../tutorial/classes.rst:356
msgid "Method Objects"
msgstr "Method 物件"
#: ../../tutorial/classes.rst:358
msgid "Usually, a method is called right after it is bound::"
msgstr "通常,一個 method 在它被連結後隨即被呼叫: ::"
#: ../../tutorial/classes.rst:360
msgid "x.f()"
msgstr "x.f()"
#: ../../tutorial/classes.rst:362
msgid ""
"If ``x = MyClass()``, as above, this will return the string ``'hello "
"world'``. However, it is not necessary to call a method right away: ``x.f`` "
"is a method object, and can be stored away and called at a later time. For "
"example::"
msgstr ""
"如果像上面一樣 ``x = MyClass()``,這將回傳字串 ``'hello world'``。然而,並沒"
"有必要立即呼叫一個 method:``x.f`` 是一個 method 物件,並且可以被儲藏起來,之"
"後再被呼叫。舉例來說: ::"
#: ../../tutorial/classes.rst:366
msgid ""
"xf = x.f\n"
"while True:\n"
" print(xf())"
msgstr ""
"xf = x.f\n"
"while True:\n"
" print(xf())"
#: ../../tutorial/classes.rst:370
msgid "will continue to print ``hello world`` until the end of time."
msgstr "將會持續印出 ``hello world`` 直到天荒地老。"
#: ../../tutorial/classes.rst:372
msgid ""
"What exactly happens when a method is called? You may have noticed that ``x."
"f()`` was called without an argument above, even though the function "
"definition for :meth:`!f` specified an argument. What happened to the "
"argument? Surely Python raises an exception when a function that requires an "
"argument is called without any --- even if the argument isn't actually "
"used..."
msgstr ""
"當一個 method 被呼叫時究竟會發生什麼事?你可能已經注意到 ``x.f()`` 被呼叫時沒"
"有任何的引數,儘管 :meth:`!f` 的函式定義有指定一個引數。這個引數發生了什麼"
"事?當一個需要引數的函式被呼叫而沒有給任何引數時,Python 肯定會引發例外——即使"
"該引數實際上沒有被使用..."
#: ../../tutorial/classes.rst:378
msgid ""
"Actually, you may have guessed the answer: the special thing about methods "
"is that the instance object is passed as the first argument of the "
"function. In our example, the call ``x.f()`` is exactly equivalent to "
"``MyClass.f(x)``. In general, calling a method with a list of *n* arguments "
"is equivalent to calling the corresponding function with an argument list "
"that is created by inserting the method's instance object before the first "
"argument."
msgstr ""
"事實上,你可能已經猜到了答案:method 的特殊之處在於,實例物件會作為函式中的第"
"一個引數被傳遞。在我們的例子中,``x.f()`` 這個呼叫等同於 ``MyClass.f(x)``。一"
"般來說,呼叫一個有 *n* 個引數的 method,等同於呼叫一個對應函式,其引數列表 "
"(argument list) 被建立時,會在第一個引數前插入該 method 的實例物件。"
#: ../../tutorial/classes.rst:385
msgid ""
"In general, methods work as follows. When a non-data attribute of an "
"instance is referenced, the instance's class is searched. If the name "
"denotes a valid class attribute that is a function object, references to "
"both the instance object and the function object are packed into a method "
"object. When the method object is called with an argument list, a new "
"argument list is constructed from the instance object and the argument list, "
"and the function object is called with this new argument list."
msgstr ""
"一般來說,方法的工作原理如下。當一個實例的非資料屬性被參照時,將會搜尋該實例"
"的 class。如果該名稱是一個有效的 class 屬性,而且是一個函式物件,則對實例物件"
"和函式物件的參照都會被打包到方法物件中。當使用引數串列呼叫方法物件時,會根據"
"實例物件和引數串列來建構一個新的引數串列,並使用該新引數串列來呼叫函式物件。"
#: ../../tutorial/classes.rst:398
msgid "Class and Instance Variables"
msgstr "Class 及實例變數"
#: ../../tutorial/classes.rst:400
msgid ""
"Generally speaking, instance variables are for data unique to each instance "
"and class variables are for attributes and methods shared by all instances "
"of the class::"
msgstr ""
"一般來說,實例變數用於每一個實例的獨特資料,而 class 變數用於該 class 的所有"
"實例共享的屬性和 method: ::"
#: ../../tutorial/classes.rst:404
msgid ""
"class Dog:\n"
"\n"
" kind = 'canine' # class variable shared by all instances\n"
"\n"
" def __init__(self, name):\n"
" self.name = name # instance variable unique to each instance\n"
"\n"
">>> d = Dog('Fido')\n"
">>> e = Dog('Buddy')\n"
">>> d.kind # shared by all dogs\n"
"'canine'\n"
">>> e.kind # shared by all dogs\n"
"'canine'\n"
">>> d.name # unique to d\n"
"'Fido'\n"
">>> e.name # unique to e\n"
"'Buddy'"
msgstr ""
"class Dog:\n"
"\n"
" kind = 'canine' # 所有實例共享的類別變數\n"
"\n"
" def __init__(self, name):\n"
" self.name = name # 每個實例獨有的實例變數\n"
"\n"
">>> d = Dog('Fido')\n"
">>> e = Dog('Buddy')\n"
">>> d.kind # 為所有 Dog 實例所共享\n"
"'canine'\n"
">>> e.kind # 為所有 Dog 實例所共享\n"
"'canine'\n"
">>> d.name # d 獨有\n"
"'Fido'\n"
">>> e.name # e 獨有\n"
"'Buddy'"
#: ../../tutorial/classes.rst:422
msgid ""
"As discussed in :ref:`tut-object`, shared data can have possibly surprising "
"effects involving :term:`mutable` objects such as lists and dictionaries. "
"For example, the *tricks* list in the following code should not be used as a "
"class variable because just a single list would be shared by all *Dog* "
"instances::"
msgstr ""
"如同在\\ :ref:`tut-object`\\ 的討論,共享的資料若涉及 :term:`mutable` 物件,"
"如 list 和 dictionary,可能會產生意外的影響。舉例來說,下列程式碼的 *tricks* "
"list 不應該作為一個 class 變數使用,因為這個 list 將會被所有的 *Dog* 實例所共"
"享: ::"
#: ../../tutorial/classes.rst:428
msgid ""
"class Dog:\n"
"\n"
" tricks = [] # mistaken use of a class variable\n"
"\n"
" def __init__(self, name):\n"
" self.name = name\n"
"\n"
" def add_trick(self, trick):\n"
" self.tricks.append(trick)\n"
"\n"
">>> d = Dog('Fido')\n"
">>> e = Dog('Buddy')\n"
">>> d.add_trick('roll over')\n"
">>> e.add_trick('play dead')\n"
">>> d.tricks # unexpectedly shared by all dogs\n"
"['roll over', 'play dead']"
msgstr ""
"class Dog:\n"
"\n"
" tricks = [] # 誤用類別變數\n"
"\n"
" def __init__(self, name):\n"
" self.name = name\n"
"\n"
" def add_trick(self, trick):\n"
" self.tricks.append(trick)\n"
"\n"
">>> d = Dog('Fido')\n"
">>> e = Dog('Buddy')\n"
">>> d.add_trick('roll over')\n"
">>> e.add_trick('play dead')\n"
">>> d.tricks # 出乎意料地被所有 dog 共享\n"
"['roll over', 'play dead']"
#: ../../tutorial/classes.rst:445
msgid "Correct design of the class should use an instance variable instead::"
msgstr "正確的 class 設計應該使用實例變數: ::"
#: ../../tutorial/classes.rst:447
msgid ""
"class Dog:\n"
"\n"
" def __init__(self, name):\n"
" self.name = name\n"
" self.tricks = [] # creates a new empty list for each dog\n"
"\n"
" def add_trick(self, trick):\n"
" self.tricks.append(trick)\n"
"\n"
">>> d = Dog('Fido')\n"
">>> e = Dog('Buddy')\n"
">>> d.add_trick('roll over')\n"
">>> e.add_trick('play dead')\n"
">>> d.tricks\n"
"['roll over']\n"
">>> e.tricks\n"
"['play dead']"
msgstr ""
"class Dog:\n"
"\n"
" def __init__(self, name):\n"
" self.name = name\n"
" self.tricks = [] # 為每一個 dog 建立空 list\n"
"\n"
" def add_trick(self, trick):\n"
" self.tricks.append(trick)\n"
"\n"
">>> d = Dog('Fido')\n"
">>> e = Dog('Buddy')\n"
">>> d.add_trick('roll over')\n"
">>> e.add_trick('play dead')\n"
">>> d.tricks\n"
"['roll over']\n"
">>> e.tricks\n"
"['play dead']"
#: ../../tutorial/classes.rst:469
msgid "Random Remarks"
msgstr "隨意的備註"
#: ../../tutorial/classes.rst:473
msgid ""
"If the same attribute name occurs in both an instance and in a class, then "
"attribute lookup prioritizes the instance::"
msgstr ""
"如果屬性名稱同時出現在一個實例和一個 class 中,則屬性的尋找會以實例為優"
"先: ::"
#: ../../tutorial/classes.rst:476
msgid ""
">>> class Warehouse:\n"
"... purpose = 'storage'\n"
"... region = 'west'\n"
"...\n"
">>> w1 = Warehouse()\n"
">>> print(w1.purpose, w1.region)\n"
"storage west\n"
">>> w2 = Warehouse()\n"
">>> w2.region = 'east'\n"
">>> print(w2.purpose, w2.region)\n"
"storage east"
msgstr ""
">>> class Warehouse:\n"
"... purpose = 'storage'\n"
"... region = 'west'\n"
"...\n"
">>> w1 = Warehouse()\n"
">>> print(w1.purpose, w1.region)\n"
"storage west\n"
">>> w2 = Warehouse()\n"
">>> w2.region = 'east'\n"
">>> print(w2.purpose, w2.region)\n"
"storage east"
#: ../../tutorial/classes.rst:488
msgid ""
"Data attributes may be referenced by methods as well as by ordinary users "
"(\"clients\") of an object. In other words, classes are not usable to "
"implement pure abstract data types. In fact, nothing in Python makes it "
"possible to enforce data hiding --- it is all based upon convention. (On "
"the other hand, the Python implementation, written in C, can completely hide "
"implementation details and control access to an object if necessary; this "
"can be used by extensions to Python written in C.)"
msgstr ""
"資料屬性可能被 method 或是被物件的一般使用者(「用戶端」)所參照。也就是說,"
"class 不可用於實作純粹抽象的資料型別。事實上,在 Python 中沒有任何可能的方"
"法,可強制隱藏資料——這都是基於慣例。(另一方面,以 C 編寫的 Python 實作可以完"
"全隱藏實作細節並且在必要時控制物件的存取;這可以被以 C 編寫的 Python 擴充所使"
"用。)"
#: ../../tutorial/classes.rst:496
msgid ""
"Clients should use data attributes with care --- clients may mess up "
"invariants maintained by the methods by stamping on their data attributes. "
"Note that clients may add data attributes of their own to an instance object "
"without affecting the validity of the methods, as long as name conflicts are "
"avoided --- again, a naming convention can save a lot of headaches here."
msgstr ""
"用戶端應該小心使用資料屬性——用戶端可能會因為覆寫他們的資料屬性,而破壞了被 "
"method 維護的不變性。注意,用戶端可以增加他們自己的資料屬性到實例物件,但不影"
"響 method 的有效性,只要避免名稱衝突即可——再一次提醒,命名慣例可以在這裡節省"
"很多麻煩。"