-
-
Notifications
You must be signed in to change notification settings - Fork 211
/
Copy path2.7.po
3975 lines (3477 loc) · 145 KB
/
2.7.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-2024, Python Software Foundation
# This file is distributed under the same license as the Python package.
#
# Translators:
msgid ""
msgstr ""
"Project-Id-Version: Python 3.13\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2025-02-05 00:13+0000\n"
"PO-Revision-Date: 2018-05-23 16:20+0000\n"
"Last-Translator: Adrian Liaw <[email protected]>\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"
#: ../../whatsnew/2.7.rst:3
msgid "What's New in Python 2.7"
msgstr "Python 2.7 有什麼新功能"
#: ../../whatsnew/2.7.rst:0
msgid "Author"
msgstr "作者"
#: ../../whatsnew/2.7.rst:5
msgid "A.M. Kuchling (amk at amk.ca)"
msgstr "A.M. Kuchling (amk at amk.ca)"
#: ../../whatsnew/2.7.rst:52
msgid ""
"This article explains the new features in Python 2.7. Python 2.7 was "
"released on July 3, 2010."
msgstr ""
#: ../../whatsnew/2.7.rst:55
msgid ""
"Numeric handling has been improved in many ways, for both floating-point "
"numbers and for the :class:`~decimal.Decimal` class. There are some useful "
"additions to the standard library, such as a greatly enhanced :mod:"
"`unittest` module, the :mod:`argparse` module for parsing command-line "
"options, convenient :class:`~collections.OrderedDict` and :class:"
"`~collections.Counter` classes in the :mod:`collections` module, and many "
"other improvements."
msgstr ""
#: ../../whatsnew/2.7.rst:63
msgid ""
"Python 2.7 is planned to be the last of the 2.x releases, so we worked on "
"making it a good release for the long term. To help with porting to Python "
"3, several new features from the Python 3.x series have been included in 2.7."
msgstr ""
#: ../../whatsnew/2.7.rst:68
msgid ""
"This article doesn't attempt to provide a complete specification of the new "
"features, but instead provides a convenient overview. For full details, you "
"should refer to the documentation for Python 2.7 at https://docs.python.org. "
"If you want to understand the rationale for the design and implementation, "
"refer to the PEP for a particular new feature or the issue on https://bugs."
"python.org in which a change was discussed. Whenever possible, \"What's New "
"in Python\" links to the bug/patch item for each change."
msgstr ""
#: ../../whatsnew/2.7.rst:80
msgid "The Future for Python 2.x"
msgstr "Python 2.x 的未來"
#: ../../whatsnew/2.7.rst:82
msgid ""
"Python 2.7 is the last major release in the 2.x series, as the Python "
"maintainers have shifted the focus of their new feature development efforts "
"to the Python 3.x series. This means that while Python 2 continues to "
"receive bug fixes, and to be updated to build correctly on new hardware and "
"versions of supported operated systems, there will be no new full feature "
"releases for the language or standard library."
msgstr ""
#: ../../whatsnew/2.7.rst:89
msgid ""
"However, while there is a large common subset between Python 2.7 and Python "
"3, and many of the changes involved in migrating to that common subset, or "
"directly to Python 3, can be safely automated, some other changes (notably "
"those associated with Unicode handling) may require careful consideration, "
"and preferably robust automated regression test suites, to migrate "
"effectively."
msgstr ""
#: ../../whatsnew/2.7.rst:96
msgid ""
"This means that Python 2.7 will remain in place for a long time, providing a "
"stable and supported base platform for production systems that have not yet "
"been ported to Python 3. The full expected lifecycle of the Python 2.7 "
"series is detailed in :pep:`373`."
msgstr ""
#: ../../whatsnew/2.7.rst:101
msgid "Some key consequences of the long-term significance of 2.7 are:"
msgstr ""
#: ../../whatsnew/2.7.rst:103
msgid ""
"As noted above, the 2.7 release has a much longer period of maintenance when "
"compared to earlier 2.x versions. Python 2.7 is currently expected to remain "
"supported by the core development team (receiving security updates and other "
"bug fixes) until at least 2020 (10 years after its initial release, compared "
"to the more typical support period of 18--24 months)."
msgstr ""
#: ../../whatsnew/2.7.rst:109
msgid ""
"As the Python 2.7 standard library ages, making effective use of the Python "
"Package Index (either directly or via a redistributor) becomes more "
"important for Python 2 users. In addition to a wide variety of third party "
"packages for various tasks, the available packages include backports of new "
"modules and features from the Python 3 standard library that are compatible "
"with Python 2, as well as various tools and libraries that can make it "
"easier to migrate to Python 3. The `Python Packaging User Guide <https://"
"packaging.python.org>`__ provides guidance on downloading and installing "
"software from the Python Package Index."
msgstr ""
#: ../../whatsnew/2.7.rst:119
msgid ""
"While the preferred approach to enhancing Python 2 is now the publication of "
"new packages on the Python Package Index, this approach doesn't necessarily "
"work in all cases, especially those related to network security. In "
"exceptional cases that cannot be handled adequately by publishing new or "
"updated packages on PyPI, the Python Enhancement Proposal process may be "
"used to make the case for adding new features directly to the Python 2 "
"standard library. Any such additions, and the maintenance releases where "
"they were added, will be noted in the :ref:`py27-maintenance-enhancements` "
"section below."
msgstr ""
#: ../../whatsnew/2.7.rst:129
msgid ""
"For projects wishing to migrate from Python 2 to Python 3, or for library "
"and framework developers wishing to support users on both Python 2 and "
"Python 3, there are a variety of tools and guides available to help decide "
"on a suitable approach and manage some of the technical details involved. "
"The recommended starting point is the :ref:`pyporting-howto` HOWTO guide."
msgstr ""
#: ../../whatsnew/2.7.rst:137
msgid "Changes to the Handling of Deprecation Warnings"
msgstr ""
#: ../../whatsnew/2.7.rst:139
msgid ""
"For Python 2.7, a policy decision was made to silence warnings only of "
"interest to developers by default. :exc:`DeprecationWarning` and its "
"descendants are now ignored unless otherwise requested, preventing users "
"from seeing warnings triggered by an application. This change was also made "
"in the branch that became Python 3.2. (Discussed on stdlib-sig and carried "
"out in :issue:`7319`.)"
msgstr ""
#: ../../whatsnew/2.7.rst:146
msgid ""
"In previous releases, :exc:`DeprecationWarning` messages were enabled by "
"default, providing Python developers with a clear indication of where their "
"code may break in a future major version of Python."
msgstr ""
#: ../../whatsnew/2.7.rst:151
msgid ""
"However, there are increasingly many users of Python-based applications who "
"are not directly involved in the development of those applications. :exc:"
"`DeprecationWarning` messages are irrelevant to such users, making them "
"worry about an application that's actually working correctly and burdening "
"application developers with responding to these concerns."
msgstr ""
#: ../../whatsnew/2.7.rst:158
msgid ""
"You can re-enable display of :exc:`DeprecationWarning` messages by running "
"Python with the :option:`-Wdefault <-W>` (short form: :option:`-Wd <-W>`) "
"switch, or by setting the :envvar:`PYTHONWARNINGS` environment variable to "
"``\"default\"`` (or ``\"d\"``) before running Python. Python code can also "
"re-enable them by calling ``warnings.simplefilter('default')``."
msgstr ""
#: ../../whatsnew/2.7.rst:165
msgid ""
"The ``unittest`` module also automatically reenables deprecation warnings "
"when running tests."
msgstr ""
#: ../../whatsnew/2.7.rst:170
msgid "Python 3.1 Features"
msgstr ""
#: ../../whatsnew/2.7.rst:172
msgid ""
"Much as Python 2.6 incorporated features from Python 3.0, version 2.7 "
"incorporates some of the new features in Python 3.1. The 2.x series "
"continues to provide tools for migrating to the 3.x series."
msgstr ""
#: ../../whatsnew/2.7.rst:177
msgid "A partial list of 3.1 features that were backported to 2.7:"
msgstr ""
#: ../../whatsnew/2.7.rst:179
msgid "The syntax for set literals (``{1,2,3}`` is a mutable set)."
msgstr ""
#: ../../whatsnew/2.7.rst:180
msgid "Dictionary and set comprehensions (``{i: i*2 for i in range(3)}``)."
msgstr ""
#: ../../whatsnew/2.7.rst:181
msgid "Multiple context managers in a single :keyword:`with` statement."
msgstr ""
#: ../../whatsnew/2.7.rst:182
msgid "A new version of the :mod:`io` library, rewritten in C for performance."
msgstr ""
#: ../../whatsnew/2.7.rst:183
msgid "The ordered-dictionary type described in :ref:`pep-0372`."
msgstr ""
#: ../../whatsnew/2.7.rst:184
msgid "The new ``\",\"`` format specifier described in :ref:`pep-0378`."
msgstr ""
#: ../../whatsnew/2.7.rst:185
msgid "The :class:`memoryview` object."
msgstr ":class:`memoryview` 物件。"
#: ../../whatsnew/2.7.rst:186
msgid ""
"A small subset of the :mod:`importlib` module, `described below <#importlib-"
"section>`__."
msgstr ""
#: ../../whatsnew/2.7.rst:188
msgid ""
"The :func:`repr` of a float ``x`` is shorter in many cases: it's now based "
"on the shortest decimal string that's guaranteed to round back to ``x``. As "
"in previous versions of Python, it's guaranteed that ``float(repr(x))`` "
"recovers ``x``."
msgstr ""
#: ../../whatsnew/2.7.rst:192
msgid ""
"Float-to-string and string-to-float conversions are correctly rounded. The :"
"func:`round` function is also now correctly rounded."
msgstr ""
#: ../../whatsnew/2.7.rst:194
msgid ""
"The :c:type:`PyCapsule` type, used to provide a C API for extension modules."
msgstr ""
#: ../../whatsnew/2.7.rst:195
msgid "The :c:func:`PyLong_AsLongAndOverflow` C API function."
msgstr ":c:func:`PyLong_AsLongAndOverflow` C API 函式。"
#: ../../whatsnew/2.7.rst:197
msgid "Other new Python3-mode warnings include:"
msgstr ""
#: ../../whatsnew/2.7.rst:199
msgid ""
":func:`!operator.isCallable` and :func:`!operator.sequenceIncludes`, which "
"are not supported in 3.x, now trigger warnings."
msgstr ""
#: ../../whatsnew/2.7.rst:201
msgid ""
"The :option:`!-3` switch now automatically enables the :option:`!-Qwarn` "
"switch that causes warnings about using classic division with integers and "
"long integers."
msgstr ""
#: ../../whatsnew/2.7.rst:214
msgid "PEP 372: Adding an Ordered Dictionary to collections"
msgstr ""
#: ../../whatsnew/2.7.rst:216
msgid ""
"Regular Python dictionaries iterate over key/value pairs in arbitrary order. "
"Over the years, a number of authors have written alternative implementations "
"that remember the order that the keys were originally inserted. Based on "
"the experiences from those implementations, 2.7 introduces a new :class:"
"`~collections.OrderedDict` class in the :mod:`collections` module."
msgstr ""
#: ../../whatsnew/2.7.rst:222
msgid ""
"The :class:`~collections.OrderedDict` API provides the same interface as "
"regular dictionaries but iterates over keys and values in a guaranteed order "
"depending on when a key was first inserted::"
msgstr ""
#: ../../whatsnew/2.7.rst:226
msgid ""
">>> from collections import OrderedDict\n"
">>> d = OrderedDict([('first', 1),\n"
"... ('second', 2),\n"
"... ('third', 3)])\n"
">>> d.items()\n"
"[('first', 1), ('second', 2), ('third', 3)]"
msgstr ""
">>> from collections import OrderedDict\n"
">>> d = OrderedDict([('first', 1),\n"
"... ('second', 2),\n"
"... ('third', 3)])\n"
">>> d.items()\n"
"[('first', 1), ('second', 2), ('third', 3)]"
#: ../../whatsnew/2.7.rst:233
msgid ""
"If a new entry overwrites an existing entry, the original insertion position "
"is left unchanged::"
msgstr ""
#: ../../whatsnew/2.7.rst:236
msgid ""
">>> d['second'] = 4\n"
">>> d.items()\n"
"[('first', 1), ('second', 4), ('third', 3)]"
msgstr ""
">>> d['second'] = 4\n"
">>> d.items()\n"
"[('first', 1), ('second', 4), ('third', 3)]"
#: ../../whatsnew/2.7.rst:240
msgid "Deleting an entry and reinserting it will move it to the end::"
msgstr ""
#: ../../whatsnew/2.7.rst:242
msgid ""
">>> del d['second']\n"
">>> d['second'] = 5\n"
">>> d.items()\n"
"[('first', 1), ('third', 3), ('second', 5)]"
msgstr ""
">>> del d['second']\n"
">>> d['second'] = 5\n"
">>> d.items()\n"
"[('first', 1), ('third', 3), ('second', 5)]"
#: ../../whatsnew/2.7.rst:247
msgid ""
"The :meth:`~collections.OrderedDict.popitem` method has an optional *last* "
"argument that defaults to ``True``. If *last* is true, the most recently "
"added key is returned and removed; if it's false, the oldest key is "
"selected::"
msgstr ""
#: ../../whatsnew/2.7.rst:252
msgid ""
">>> od = OrderedDict([(x,0) for x in range(20)])\n"
">>> od.popitem()\n"
"(19, 0)\n"
">>> od.popitem()\n"
"(18, 0)\n"
">>> od.popitem(last=False)\n"
"(0, 0)\n"
">>> od.popitem(last=False)\n"
"(1, 0)"
msgstr ""
">>> od = OrderedDict([(x,0) for x in range(20)])\n"
">>> od.popitem()\n"
"(19, 0)\n"
">>> od.popitem()\n"
"(18, 0)\n"
">>> od.popitem(last=False)\n"
"(0, 0)\n"
">>> od.popitem(last=False)\n"
"(1, 0)"
#: ../../whatsnew/2.7.rst:262
msgid ""
"Comparing two ordered dictionaries checks both the keys and values, and "
"requires that the insertion order was the same::"
msgstr ""
#: ../../whatsnew/2.7.rst:265
msgid ""
">>> od1 = OrderedDict([('first', 1),\n"
"... ('second', 2),\n"
"... ('third', 3)])\n"
">>> od2 = OrderedDict([('third', 3),\n"
"... ('first', 1),\n"
"... ('second', 2)])\n"
">>> od1 == od2\n"
"False\n"
">>> # Move 'third' key to the end\n"
">>> del od2['third']; od2['third'] = 3\n"
">>> od1 == od2\n"
"True"
msgstr ""
">>> od1 = OrderedDict([('first', 1),\n"
"... ('second', 2),\n"
"... ('third', 3)])\n"
">>> od2 = OrderedDict([('third', 3),\n"
"... ('first', 1),\n"
"... ('second', 2)])\n"
">>> od1 == od2\n"
"False\n"
">>> # Move 'third' key to the end\n"
">>> del od2['third']; od2['third'] = 3\n"
">>> od1 == od2\n"
"True"
#: ../../whatsnew/2.7.rst:278
msgid ""
"Comparing an :class:`~collections.OrderedDict` with a regular dictionary "
"ignores the insertion order and just compares the keys and values."
msgstr ""
#: ../../whatsnew/2.7.rst:281
msgid ""
"How does the :class:`~collections.OrderedDict` work? It maintains a doubly "
"linked list of keys, appending new keys to the list as they're inserted. A "
"secondary dictionary maps keys to their corresponding list node, so deletion "
"doesn't have to traverse the entire linked list and therefore remains *O*\\ "
"(1)."
msgstr ""
#: ../../whatsnew/2.7.rst:287
msgid ""
"The standard library now supports use of ordered dictionaries in several "
"modules."
msgstr ""
#: ../../whatsnew/2.7.rst:290
msgid ""
"The :mod:`ConfigParser <configparser>` module uses them by default, meaning "
"that configuration files can now be read, modified, and then written back in "
"their original order."
msgstr ""
#: ../../whatsnew/2.7.rst:294
msgid ""
"The :meth:`~collections.somenamedtuple._asdict` method for :func:"
"`collections.namedtuple` now returns an ordered dictionary with the values "
"appearing in the same order as the underlying tuple indices."
msgstr ""
#: ../../whatsnew/2.7.rst:298
msgid ""
"The :mod:`json` module's :class:`~json.JSONDecoder` class constructor was "
"extended with an *object_pairs_hook* parameter to allow :class:`OrderedDict` "
"instances to be built by the decoder. Support was also added for third-party "
"tools like `PyYAML <https://pyyaml.org/>`_."
msgstr ""
#: ../../whatsnew/2.7.rst:306
msgid ":pep:`372` - Adding an ordered dictionary to collections"
msgstr ""
#: ../../whatsnew/2.7.rst:307
msgid ""
"PEP written by Armin Ronacher and Raymond Hettinger; implemented by Raymond "
"Hettinger."
msgstr ""
#: ../../whatsnew/2.7.rst:313
msgid "PEP 378: Format Specifier for Thousands Separator"
msgstr ""
#: ../../whatsnew/2.7.rst:315
msgid ""
"To make program output more readable, it can be useful to add separators to "
"large numbers, rendering them as 18,446,744,073,709,551,616 instead of "
"18446744073709551616."
msgstr ""
#: ../../whatsnew/2.7.rst:319
msgid ""
"The fully general solution for doing this is the :mod:`locale` module, which "
"can use different separators (\",\" in North America, \".\" in Europe) and "
"different grouping sizes, but :mod:`locale` is complicated to use and "
"unsuitable for multi-threaded applications where different threads are "
"producing output for different locales."
msgstr ""
#: ../../whatsnew/2.7.rst:325
msgid ""
"Therefore, a simple comma-grouping mechanism has been added to the mini-"
"language used by the :meth:`str.format` method. When formatting a floating-"
"point number, simply include a comma between the width and the precision::"
msgstr ""
#: ../../whatsnew/2.7.rst:330
msgid ""
">>> '{:20,.2f}'.format(18446744073709551616.0)\n"
"'18,446,744,073,709,551,616.00'"
msgstr ""
">>> '{:20,.2f}'.format(18446744073709551616.0)\n"
"'18,446,744,073,709,551,616.00'"
#: ../../whatsnew/2.7.rst:333
msgid "When formatting an integer, include the comma after the width:"
msgstr ""
#: ../../whatsnew/2.7.rst:338
msgid ""
"This mechanism is not adaptable at all; commas are always used as the "
"separator and the grouping is always into three-digit groups. The comma-"
"formatting mechanism isn't as general as the :mod:`locale` module, but it's "
"easier to use."
msgstr ""
#: ../../whatsnew/2.7.rst:345
msgid ":pep:`378` - Format Specifier for Thousands Separator"
msgstr ""
#: ../../whatsnew/2.7.rst:346
msgid "PEP written by Raymond Hettinger; implemented by Eric Smith."
msgstr "由 Raymond Hettinger 撰寫 PEP;由 Eric Smith 實作。"
#: ../../whatsnew/2.7.rst:349
msgid "PEP 389: The argparse Module for Parsing Command Lines"
msgstr ""
#: ../../whatsnew/2.7.rst:351
msgid ""
"The :mod:`argparse` module for parsing command-line arguments was added as a "
"more powerful replacement for the :mod:`optparse` module."
msgstr ""
#: ../../whatsnew/2.7.rst:355
msgid ""
"This means Python now supports three different modules for parsing command-"
"line arguments: :mod:`getopt`, :mod:`optparse`, and :mod:`argparse`. The :"
"mod:`getopt` module closely resembles the C library's :c:func:`!getopt` "
"function, so it remains useful if you're writing a Python prototype that "
"will eventually be rewritten in C. :mod:`optparse` becomes redundant, but "
"there are no plans to remove it because there are many scripts still using "
"it, and there's no automated way to update these scripts. (Making the :mod:"
"`argparse` API consistent with :mod:`optparse`'s interface was discussed but "
"rejected as too messy and difficult.)"
msgstr ""
#: ../../whatsnew/2.7.rst:366
msgid ""
"In short, if you're writing a new script and don't need to worry about "
"compatibility with earlier versions of Python, use :mod:`argparse` instead "
"of :mod:`optparse`."
msgstr ""
#: ../../whatsnew/2.7.rst:370
msgid "Here's an example::"
msgstr "以下是個範例: ::"
#: ../../whatsnew/2.7.rst:372
msgid ""
"import argparse\n"
"\n"
"parser = argparse.ArgumentParser(description='Command-line example.')\n"
"\n"
"# Add optional switches\n"
"parser.add_argument('-v', action='store_true', dest='is_verbose',\n"
" help='produce verbose output')\n"
"parser.add_argument('-o', action='store', dest='output',\n"
" metavar='FILE',\n"
" help='direct output to FILE instead of stdout')\n"
"parser.add_argument('-C', action='store', type=int, dest='context',\n"
" metavar='NUM', default=0,\n"
" help='display NUM lines of added context')\n"
"\n"
"# Allow any number of additional arguments.\n"
"parser.add_argument(nargs='*', action='store', dest='inputs',\n"
" help='input filenames (default is stdin)')\n"
"\n"
"args = parser.parse_args()\n"
"print args.__dict__"
msgstr ""
#: ../../whatsnew/2.7.rst:393
msgid ""
"Unless you override it, :option:`!-h` and :option:`!--help` switches are "
"automatically added, and produce neatly formatted output::"
msgstr ""
#: ../../whatsnew/2.7.rst:396
msgid ""
"-> ./python.exe argparse-example.py --help\n"
"usage: argparse-example.py [-h] [-v] [-o FILE] [-C NUM] [inputs "
"[inputs ...]]\n"
"\n"
"Command-line example.\n"
"\n"
"positional arguments:\n"
" inputs input filenames (default is stdin)\n"
"\n"
"optional arguments:\n"
" -h, --help show this help message and exit\n"
" -v produce verbose output\n"
" -o FILE direct output to FILE instead of stdout\n"
" -C NUM display NUM lines of added context"
msgstr ""
"-> ./python.exe argparse-example.py --help\n"
"usage: argparse-example.py [-h] [-v] [-o FILE] [-C NUM] [inputs "
"[inputs ...]]\n"
"\n"
"Command-line example.\n"
"\n"
"positional arguments:\n"
" inputs input filenames (default is stdin)\n"
"\n"
"optional arguments:\n"
" -h, --help show this help message and exit\n"
" -v produce verbose output\n"
" -o FILE direct output to FILE instead of stdout\n"
" -C NUM display NUM lines of added context"
#: ../../whatsnew/2.7.rst:410
msgid ""
"As with :mod:`optparse`, the command-line switches and arguments are "
"returned as an object with attributes named by the *dest* parameters::"
msgstr ""
#: ../../whatsnew/2.7.rst:413
msgid ""
"-> ./python.exe argparse-example.py -v\n"
"{'output': None,\n"
" 'is_verbose': True,\n"
" 'context': 0,\n"
" 'inputs': []}\n"
"\n"
"-> ./python.exe argparse-example.py -v -o /tmp/output -C 4 file1 file2\n"
"{'output': '/tmp/output',\n"
" 'is_verbose': True,\n"
" 'context': 4,\n"
" 'inputs': ['file1', 'file2']}"
msgstr ""
"-> ./python.exe argparse-example.py -v\n"
"{'output': None,\n"
" 'is_verbose': True,\n"
" 'context': 0,\n"
" 'inputs': []}\n"
"\n"
"-> ./python.exe argparse-example.py -v -o /tmp/output -C 4 file1 file2\n"
"{'output': '/tmp/output',\n"
" 'is_verbose': True,\n"
" 'context': 4,\n"
" 'inputs': ['file1', 'file2']}"
#: ../../whatsnew/2.7.rst:425
msgid ""
":mod:`argparse` has much fancier validation than :mod:`optparse`; you can "
"specify an exact number of arguments as an integer, 0 or more arguments by "
"passing ``'*'``, 1 or more by passing ``'+'``, or an optional argument with "
"``'?'``. A top-level parser can contain sub-parsers to define subcommands "
"that have different sets of switches, as in ``svn commit``, ``svn "
"checkout``, etc. You can specify an argument's type as :class:`~argparse."
"FileType`, which will automatically open files for you and understands that "
"``'-'`` means standard input or output."
msgstr ""
#: ../../whatsnew/2.7.rst:437
msgid ":mod:`argparse` documentation"
msgstr ":mod:`argparse` 文件"
#: ../../whatsnew/2.7.rst:438
msgid "The documentation page of the argparse module."
msgstr "argparse 模組的文件頁面。"
#: ../../whatsnew/2.7.rst:440
msgid ":ref:`upgrading-optparse-code`"
msgstr ":ref:`upgrading-optparse-code`"
#: ../../whatsnew/2.7.rst:441
msgid ""
"Part of the Python documentation, describing how to convert code that uses :"
"mod:`optparse`."
msgstr ""
#: ../../whatsnew/2.7.rst:444
msgid ":pep:`389` - argparse - New Command Line Parsing Module"
msgstr ""
#: ../../whatsnew/2.7.rst:445
msgid "PEP written and implemented by Steven Bethard."
msgstr "由 Steven Bethard 撰寫 PEP 與實作。"
#: ../../whatsnew/2.7.rst:448
msgid "PEP 391: Dictionary-Based Configuration For Logging"
msgstr ""
#: ../../whatsnew/2.7.rst:450
msgid ""
"The :mod:`logging` module is very flexible; applications can define a tree "
"of logging subsystems, and each logger in this tree can filter out certain "
"messages, format them differently, and direct messages to a varying number "
"of handlers."
msgstr ""
#: ../../whatsnew/2.7.rst:455
msgid ""
"All this flexibility can require a lot of configuration. You can write "
"Python statements to create objects and set their properties, but a complex "
"set-up requires verbose but boring code. :mod:`logging` also supports a :"
"func:`~logging.config.fileConfig` function that parses a file, but the file "
"format doesn't support configuring filters, and it's messier to generate "
"programmatically."
msgstr ""
#: ../../whatsnew/2.7.rst:462
msgid ""
"Python 2.7 adds a :func:`~logging.config.dictConfig` function that uses a "
"dictionary to configure logging. There are many ways to produce a "
"dictionary from different sources: construct one with code; parse a file "
"containing JSON; or use a YAML parsing library if one is installed. For "
"more information see :ref:`logging-config-api`."
msgstr ""
#: ../../whatsnew/2.7.rst:468
msgid ""
"The following example configures two loggers, the root logger and a logger "
"named \"network\". Messages sent to the root logger will be sent to the "
"system log using the syslog protocol, and messages to the \"network\" logger "
"will be written to a :file:`network.log` file that will be rotated once the "
"log reaches 1MB."
msgstr ""
#: ../../whatsnew/2.7.rst:476
msgid ""
"import logging\n"
"import logging.config\n"
"\n"
"configdict = {\n"
" 'version': 1, # Configuration schema in use; must be 1 for now\n"
" 'formatters': {\n"
" 'standard': {\n"
" 'format': ('%(asctime)s %(name)-15s '\n"
" '%(levelname)-8s %(message)s')}},\n"
"\n"
" 'handlers': {'netlog': {'backupCount': 10,\n"
" 'class': 'logging.handlers.RotatingFileHandler',\n"
" 'filename': '/logs/network.log',\n"
" 'formatter': 'standard',\n"
" 'level': 'INFO',\n"
" 'maxBytes': 1000000},\n"
" 'syslog': {'class': 'logging.handlers.SysLogHandler',\n"
" 'formatter': 'standard',\n"
" 'level': 'ERROR'}},\n"
"\n"
" # Specify all the subordinate loggers\n"
" 'loggers': {\n"
" 'network': {\n"
" 'handlers': ['netlog']\n"
" }\n"
" },\n"
" # Specify properties of the root logger\n"
" 'root': {\n"
" 'handlers': ['syslog']\n"
" },\n"
"}\n"
"\n"
"# Set up configuration\n"
"logging.config.dictConfig(configdict)\n"
"\n"
"# As an example, log two error messages\n"
"logger = logging.getLogger('/')\n"
"logger.error('Database not found')\n"
"\n"
"netlogger = logging.getLogger('network')\n"
"netlogger.error('Connection failed')"
msgstr ""
#: ../../whatsnew/2.7.rst:518
msgid ""
"Three smaller enhancements to the :mod:`logging` module, all implemented by "
"Vinay Sajip, are:"
msgstr ""
#: ../../whatsnew/2.7.rst:523
msgid ""
"The :class:`~logging.handlers.SysLogHandler` class now supports syslogging "
"over TCP. The constructor has a *socktype* parameter giving the type of "
"socket to use, either :const:`socket.SOCK_DGRAM` for UDP or :const:`socket."
"SOCK_STREAM` for TCP. The default protocol remains UDP."
msgstr ""
#: ../../whatsnew/2.7.rst:529
msgid ""
":class:`~logging.Logger` instances gained a :meth:`~logging.Logger.getChild` "
"method that retrieves a descendant logger using a relative path. For "
"example, once you retrieve a logger by doing ``log = getLogger('app')``, "
"calling ``log.getChild('network.listen')`` is equivalent to ``getLogger('app."
"network.listen')``."
msgstr ""
#: ../../whatsnew/2.7.rst:535
msgid ""
"The :class:`~logging.LoggerAdapter` class gained an :meth:`~logging.Logger."
"isEnabledFor` method that takes a *level* and returns whether the underlying "
"logger would process a message of that level of importance."
msgstr ""
#: ../../whatsnew/2.7.rst:544
msgid ":pep:`391` - Dictionary-Based Configuration For Logging"
msgstr ""
#: ../../whatsnew/2.7.rst:545
msgid "PEP written and implemented by Vinay Sajip."
msgstr "由 Vinay Sajip 撰寫 PEP 與實作。"
#: ../../whatsnew/2.7.rst:548
msgid "PEP 3106: Dictionary Views"
msgstr ""
#: ../../whatsnew/2.7.rst:550
msgid ""
"The dictionary methods :meth:`~dict.keys`, :meth:`~dict.values`, and :meth:"
"`~dict.items` are different in Python 3.x. They return an object called a :"
"dfn:`view` instead of a fully materialized list."
msgstr ""
#: ../../whatsnew/2.7.rst:554
msgid ""
"It's not possible to change the return values of :meth:`~dict.keys`, :meth:"
"`~dict.values`, and :meth:`~dict.items` in Python 2.7 because too much code "
"would break. Instead the 3.x versions were added under the new names :meth:"
"`!viewkeys`, :meth:`!viewvalues`, and :meth:`!viewitems`."
msgstr ""
#: ../../whatsnew/2.7.rst:562
msgid ""
">>> d = dict((i*10, chr(65+i)) for i in range(26))\n"
">>> d\n"
"{0: 'A', 130: 'N', 10: 'B', 140: 'O', 20: ..., 250: 'Z'}\n"
">>> d.viewkeys()\n"
"dict_keys([0, 130, 10, 140, 20, 150, 30, ..., 250])"
msgstr ""
">>> d = dict((i*10, chr(65+i)) for i in range(26))\n"
">>> d\n"
"{0: 'A', 130: 'N', 10: 'B', 140: 'O', 20: ..., 250: 'Z'}\n"
">>> d.viewkeys()\n"
"dict_keys([0, 130, 10, 140, 20, 150, 30, ..., 250])"
#: ../../whatsnew/2.7.rst:568
msgid ""
"Views can be iterated over, but the key and item views also behave like "
"sets. The ``&`` operator performs intersection, and ``|`` performs a union::"
msgstr ""
#: ../../whatsnew/2.7.rst:572
msgid ""
">>> d1 = dict((i*10, chr(65+i)) for i in range(26))\n"
">>> d2 = dict((i**.5, i) for i in range(1000))\n"
">>> d1.viewkeys() & d2.viewkeys()\n"
"set([0.0, 10.0, 20.0, 30.0])\n"
">>> d1.viewkeys() | range(0, 30)\n"
"set([0, 1, 130, 3, 4, 5, 6, ..., 120, 250])"
msgstr ""
">>> d1 = dict((i*10, chr(65+i)) for i in range(26))\n"
">>> d2 = dict((i**.5, i) for i in range(1000))\n"
">>> d1.viewkeys() & d2.viewkeys()\n"
"set([0.0, 10.0, 20.0, 30.0])\n"
">>> d1.viewkeys() | range(0, 30)\n"
"set([0, 1, 130, 3, 4, 5, 6, ..., 120, 250])"
#: ../../whatsnew/2.7.rst:579
msgid ""
"The view keeps track of the dictionary and its contents change as the "
"dictionary is modified::"
msgstr ""
#: ../../whatsnew/2.7.rst:582
msgid ""
">>> vk = d.viewkeys()\n"
">>> vk\n"
"dict_keys([0, 130, 10, ..., 250])\n"
">>> d[260] = '&'\n"
">>> vk\n"
"dict_keys([0, 130, 260, 10, ..., 250])"
msgstr ""
">>> vk = d.viewkeys()\n"
">>> vk\n"
"dict_keys([0, 130, 10, ..., 250])\n"
">>> d[260] = '&'\n"
">>> vk\n"
"dict_keys([0, 130, 260, 10, ..., 250])"
#: ../../whatsnew/2.7.rst:589
msgid ""
"However, note that you can't add or remove keys while you're iterating over "
"the view::"
msgstr ""
#: ../../whatsnew/2.7.rst:592
msgid ""
">>> for k in vk:\n"
"... d[k*2] = k\n"
"...\n"
"Traceback (most recent call last):\n"
" File \"<stdin>\", line 1, in <module>\n"
"RuntimeError: dictionary changed size during iteration"
msgstr ""
">>> for k in vk:\n"
"... d[k*2] = k\n"
"...\n"
"Traceback (most recent call last):\n"
" File \"<stdin>\", line 1, in <module>\n"
"RuntimeError: dictionary changed size during iteration"
#: ../../whatsnew/2.7.rst:599
msgid ""
"You can use the view methods in Python 2.x code, and the 2to3 converter will "
"change them to the standard :meth:`~dict.keys`, :meth:`~dict.values`, and :"
"meth:`~dict.items` methods."
msgstr ""
#: ../../whatsnew/2.7.rst:605
msgid ":pep:`3106` - Revamping dict.keys(), .values() and .items()"
msgstr ""
#: ../../whatsnew/2.7.rst:606
msgid ""
"PEP written by Guido van Rossum. Backported to 2.7 by Alexandre Vassalotti; :"
"issue:`1967`."
msgstr ""
#: ../../whatsnew/2.7.rst:611
msgid "PEP 3137: The memoryview Object"
msgstr ""
#: ../../whatsnew/2.7.rst:613
msgid ""
"The :class:`memoryview` object provides a view of another object's memory "
"content that matches the :class:`bytes` type's interface."
msgstr ""
#: ../../whatsnew/2.7.rst:616
msgid ""
">>> import string\n"
">>> m = memoryview(string.letters)\n"
">>> m\n"
"<memory at 0x37f850>\n"
">>> len(m) # Returns length of underlying object\n"
"52\n"
">>> m[0], m[25], m[26] # Indexing returns one byte\n"
"('a', 'z', 'A')\n"
">>> m2 = m[0:26] # Slicing returns another memoryview\n"
">>> m2\n"
"<memory at 0x37f080>"
msgstr ""
#: ../../whatsnew/2.7.rst:631
msgid ""
"The content of the view can be converted to a string of bytes or a list of "
"integers:"
msgstr ""
#: ../../whatsnew/2.7.rst:634
msgid ""
">>> m2.tobytes()\n"
"'abcdefghijklmnopqrstuvwxyz'\n"
">>> m2.tolist()\n"
"[97, 98, 99, 100, 101, 102, 103, ... 121, 122]\n"
">>>"
msgstr ""
">>> m2.tobytes()\n"
"'abcdefghijklmnopqrstuvwxyz'\n"
">>> m2.tolist()\n"
"[97, 98, 99, 100, 101, 102, 103, ... 121, 122]\n"
">>>"
#: ../../whatsnew/2.7.rst:643
msgid ""
":class:`memoryview` objects allow modifying the underlying object if it's a "
"mutable object."
msgstr ""
#: ../../whatsnew/2.7.rst:646
msgid ""
">>> m2[0] = 75\n"
"Traceback (most recent call last):\n"
" File \"<stdin>\", line 1, in <module>\n"
"TypeError: cannot modify read-only memory\n"
">>> b = bytearray(string.letters) # Creating a mutable object\n"
">>> b\n"
"bytearray(b'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')\n"
">>> mb = memoryview(b)\n"
">>> mb[0] = '*' # Assign to view, changing the bytearray.\n"
">>> b[0:5] # The bytearray has been changed.\n"
"bytearray(b'*bcde')\n"
">>>"
msgstr ""
#: ../../whatsnew/2.7.rst:664
msgid ":pep:`3137` - Immutable Bytes and Mutable Buffer"
msgstr ""
#: ../../whatsnew/2.7.rst:665
msgid ""
"PEP written by Guido van Rossum. Implemented by Travis Oliphant, Antoine "
"Pitrou and others. Backported to 2.7 by Antoine Pitrou; :issue:`2396`."