-
-
Notifications
You must be signed in to change notification settings - Fork 211
/
Copy path2.4.po
2379 lines (2060 loc) · 77.6 KB
/
2.4.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.
#
# Translators:
msgid ""
msgstr ""
"Project-Id-Version: Python 3.13\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-09-24 07:20+0000\n"
"PO-Revision-Date: 2018-05-23 16:19+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.4.rst:3
msgid "What's New in Python 2.4"
msgstr "Python 2.4 有什麼新功能"
#: ../../whatsnew/2.4.rst:0
msgid "Author"
msgstr "作者"
#: ../../whatsnew/2.4.rst:5
msgid "A.M. Kuchling"
msgstr "A.M. Kuchling"
#: ../../whatsnew/2.4.rst:14
msgid ""
"This article explains the new features in Python 2.4.1, released on March "
"30, 2005."
msgstr ""
#: ../../whatsnew/2.4.rst:17
msgid ""
"Python 2.4 is a medium-sized release. It doesn't introduce as many changes "
"as the radical Python 2.2, but introduces more features than the "
"conservative 2.3 release. The most significant new language features are "
"function decorators and generator expressions; most other changes are to the "
"standard library."
msgstr ""
#: ../../whatsnew/2.4.rst:22
msgid ""
"According to the CVS change logs, there were 481 patches applied and 502 "
"bugs fixed between Python 2.3 and 2.4. Both figures are likely to be "
"underestimates."
msgstr ""
#: ../../whatsnew/2.4.rst:25
msgid ""
"This article doesn't attempt to provide a complete specification of every "
"single new feature, but instead provides a brief introduction to each "
"feature. For full details, you should refer to the documentation for Python "
"2.4, such as the Python Library Reference and the Python Reference Manual. "
"Often you will be referred to the PEP for a particular new feature for "
"explanations of the implementation and design rationale."
msgstr ""
#: ../../whatsnew/2.4.rst:36
msgid "PEP 218: Built-In Set Objects"
msgstr ""
#: ../../whatsnew/2.4.rst:38
msgid ""
"Python 2.3 introduced the :mod:`sets` module. C implementations of set data "
"types have now been added to the Python core as two new built-in types, "
"``set(iterable)`` and ``frozenset(iterable)``. They provide high speed "
"operations for membership testing, for eliminating duplicates from "
"sequences, and for mathematical operations like unions, intersections, "
"differences, and symmetric differences. ::"
msgstr ""
#: ../../whatsnew/2.4.rst:45
msgid ""
">>> a = set('abracadabra') # form a set from a string\n"
">>> 'z' in a # fast membership testing\n"
"False\n"
">>> a # unique letters in a\n"
"set(['a', 'r', 'b', 'c', 'd'])\n"
">>> ''.join(a) # convert back into a string\n"
"'arbcd'\n"
"\n"
">>> b = set('alacazam') # form a second set\n"
">>> a - b # letters in a but not in b\n"
"set(['r', 'd', 'b'])\n"
">>> a | b # letters in either a or b\n"
"set(['a', 'c', 'r', 'd', 'b', 'm', 'z', 'l'])\n"
">>> a & b # letters in both a and b\n"
"set(['a', 'c'])\n"
">>> a ^ b # letters in a or b but not both\n"
"set(['r', 'd', 'b', 'm', 'z', 'l'])\n"
"\n"
">>> a.add('z') # add a new element\n"
">>> a.update('wxy') # add multiple new elements\n"
">>> a\n"
"set(['a', 'c', 'b', 'd', 'r', 'w', 'y', 'x', 'z'])\n"
">>> a.remove('x') # take one element out\n"
">>> a\n"
"set(['a', 'c', 'b', 'd', 'r', 'w', 'y', 'z'])"
msgstr ""
#: ../../whatsnew/2.4.rst:71
msgid ""
"The :func:`frozenset` type is an immutable version of :func:`set`. Since it "
"is immutable and hashable, it may be used as a dictionary key or as a member "
"of another set."
msgstr ""
#: ../../whatsnew/2.4.rst:75
msgid ""
"The :mod:`sets` module remains in the standard library, and may be useful if "
"you wish to subclass the :class:`Set` or :class:`ImmutableSet` classes. "
"There are currently no plans to deprecate the module."
msgstr ""
#: ../../whatsnew/2.4.rst:82
msgid ":pep:`218` - Adding a Built-In Set Object Type"
msgstr ""
#: ../../whatsnew/2.4.rst:83
msgid ""
"Originally proposed by Greg Wilson and ultimately implemented by Raymond "
"Hettinger."
msgstr ""
#: ../../whatsnew/2.4.rst:90
msgid "PEP 237: Unifying Long Integers and Integers"
msgstr ""
#: ../../whatsnew/2.4.rst:92
msgid ""
"The lengthy transition process for this PEP, begun in Python 2.2, takes "
"another step forward in Python 2.4. In 2.3, certain integer operations that "
"would behave differently after int/long unification triggered :exc:"
"`FutureWarning` warnings and returned values limited to 32 or 64 bits "
"(depending on your platform). In 2.4, these expressions no longer produce a "
"warning and instead produce a different result that's usually a long integer."
msgstr ""
#: ../../whatsnew/2.4.rst:99
msgid ""
"The problematic expressions are primarily left shifts and lengthy "
"hexadecimal and octal constants. For example, ``2 << 32`` results in a "
"warning in 2.3, evaluating to 0 on 32-bit platforms. In Python 2.4, this "
"expression now returns the correct answer, 8589934592."
msgstr ""
#: ../../whatsnew/2.4.rst:107
msgid ":pep:`237` - Unifying Long Integers and Integers"
msgstr ""
#: ../../whatsnew/2.4.rst:108
msgid ""
"Original PEP written by Moshe Zadka and GvR. The changes for 2.4 were "
"implemented by Kalle Svensson."
msgstr ""
#: ../../whatsnew/2.4.rst:115
msgid "PEP 289: Generator Expressions"
msgstr ""
#: ../../whatsnew/2.4.rst:117
msgid ""
"The iterator feature introduced in Python 2.2 and the :mod:`itertools` "
"module make it easier to write programs that loop through large data sets "
"without having the entire data set in memory at one time. List "
"comprehensions don't fit into this picture very well because they produce a "
"Python list object containing all of the items. This unavoidably pulls all "
"of the objects into memory, which can be a problem if your data set is very "
"large. When trying to write a functionally styled program, it would be "
"natural to write something like::"
msgstr ""
#: ../../whatsnew/2.4.rst:125
msgid ""
"links = [link for link in get_all_links() if not link.followed]\n"
"for link in links:\n"
" ..."
msgstr ""
#: ../../whatsnew/2.4.rst:129
msgid "instead of ::"
msgstr ""
#: ../../whatsnew/2.4.rst:131
msgid ""
"for link in get_all_links():\n"
" if link.followed:\n"
" continue\n"
" ..."
msgstr ""
#: ../../whatsnew/2.4.rst:136
msgid ""
"The first form is more concise and perhaps more readable, but if you're "
"dealing with a large number of link objects you'd have to write the second "
"form to avoid having all link objects in memory at the same time."
msgstr ""
#: ../../whatsnew/2.4.rst:140
msgid ""
"Generator expressions work similarly to list comprehensions but don't "
"materialize the entire list; instead they create a generator that will "
"return elements one by one. The above example could be written as::"
msgstr ""
#: ../../whatsnew/2.4.rst:144
msgid ""
"links = (link for link in get_all_links() if not link.followed)\n"
"for link in links:\n"
" ..."
msgstr ""
#: ../../whatsnew/2.4.rst:148
msgid ""
"Generator expressions always have to be written inside parentheses, as in "
"the above example. The parentheses signalling a function call also count, "
"so if you want to create an iterator that will be immediately passed to a "
"function you could write::"
msgstr ""
#: ../../whatsnew/2.4.rst:153
msgid "print sum(obj.count for obj in list_all_objects())"
msgstr ""
#: ../../whatsnew/2.4.rst:155
msgid ""
"Generator expressions differ from list comprehensions in various small ways. "
"Most notably, the loop variable (*obj* in the above example) is not "
"accessible outside of the generator expression. List comprehensions leave "
"the variable assigned to its last value; future versions of Python will "
"change this, making list comprehensions match generator expressions in this "
"respect."
msgstr ""
#: ../../whatsnew/2.4.rst:164
msgid ":pep:`289` - Generator Expressions"
msgstr ""
#: ../../whatsnew/2.4.rst:165
msgid ""
"Proposed by Raymond Hettinger and implemented by Jiwon Seo with early "
"efforts steered by Hye-Shik Chang."
msgstr ""
#: ../../whatsnew/2.4.rst:172
msgid "PEP 292: Simpler String Substitutions"
msgstr ""
#: ../../whatsnew/2.4.rst:174
msgid ""
"Some new classes in the standard library provide an alternative mechanism "
"for substituting variables into strings; this style of substitution may be "
"better for applications where untrained users need to edit templates."
msgstr ""
#: ../../whatsnew/2.4.rst:178
msgid "The usual way of substituting variables by name is the ``%`` operator::"
msgstr ""
#: ../../whatsnew/2.4.rst:180
msgid ""
">>> '%(page)i: %(title)s' % {'page':2, 'title': 'The Best of Times'}\n"
"'2: The Best of Times'"
msgstr ""
#: ../../whatsnew/2.4.rst:183
msgid ""
"When writing the template string, it can be easy to forget the ``i`` or "
"``s`` after the closing parenthesis. This isn't a big problem if the "
"template is in a Python module, because you run the code, get an "
"\"Unsupported format character\" :exc:`ValueError`, and fix the problem. "
"However, consider an application such as Mailman where template strings or "
"translations are being edited by users who aren't aware of the Python "
"language. The format string's syntax is complicated to explain to such "
"users, and if they make a mistake, it's difficult to provide helpful "
"feedback to them."
msgstr ""
#: ../../whatsnew/2.4.rst:192
msgid ""
"PEP 292 adds a :class:`Template` class to the :mod:`string` module that uses "
"``$`` to indicate a substitution::"
msgstr ""
#: ../../whatsnew/2.4.rst:195
msgid ""
">>> import string\n"
">>> t = string.Template('$page: $title')\n"
">>> t.substitute({'page':2, 'title': 'The Best of Times'})\n"
"'2: The Best of Times'"
msgstr ""
#: ../../whatsnew/2.4.rst:200
msgid ""
"If a key is missing from the dictionary, the :meth:`substitute` method will "
"raise a :exc:`KeyError`. There's also a :meth:`safe_substitute` method that "
"ignores missing keys::"
msgstr ""
#: ../../whatsnew/2.4.rst:204
msgid ""
">>> t = string.Template('$page: $title')\n"
">>> t.safe_substitute({'page':3})\n"
"'3: $title'"
msgstr ""
#: ../../whatsnew/2.4.rst:211
msgid ":pep:`292` - Simpler String Substitutions"
msgstr ""
#: ../../whatsnew/2.4.rst:212
msgid "Written and implemented by Barry Warsaw."
msgstr ""
#: ../../whatsnew/2.4.rst:218
msgid "PEP 318: Decorators for Functions and Methods"
msgstr ""
#: ../../whatsnew/2.4.rst:220
msgid ""
"Python 2.2 extended Python's object model by adding static methods and class "
"methods, but it didn't extend Python's syntax to provide any new way of "
"defining static or class methods. Instead, you had to write a :keyword:"
"`def` statement in the usual way, and pass the resulting method to a :func:"
"`staticmethod` or :func:`classmethod` function that would wrap up the "
"function as a method of the new type. Your code would look like this::"
msgstr ""
#: ../../whatsnew/2.4.rst:227
msgid ""
"class C:\n"
" def meth (cls):\n"
" ...\n"
"\n"
" meth = classmethod(meth) # Rebind name to wrapped-up class method"
msgstr ""
#: ../../whatsnew/2.4.rst:233
msgid ""
"If the method was very long, it would be easy to miss or forget the :func:"
"`classmethod` invocation after the function body."
msgstr ""
#: ../../whatsnew/2.4.rst:236
msgid ""
"The intention was always to add some syntax to make such definitions more "
"readable, but at the time of 2.2's release a good syntax was not obvious. "
"Today a good syntax *still* isn't obvious but users are asking for easier "
"access to the feature; a new syntactic feature has been added to meet this "
"need."
msgstr ""
#: ../../whatsnew/2.4.rst:241
msgid ""
"The new feature is called \"function decorators\". The name comes from the "
"idea that :func:`classmethod`, :func:`staticmethod`, and friends are storing "
"additional information on a function object; they're *decorating* functions "
"with more details."
msgstr ""
#: ../../whatsnew/2.4.rst:246
msgid ""
"The notation borrows from Java and uses the ``'@'`` character as an "
"indicator. Using the new syntax, the example above would be written::"
msgstr ""
#: ../../whatsnew/2.4.rst:249
msgid ""
"class C:\n"
"\n"
" @classmethod\n"
" def meth (cls):\n"
" ..."
msgstr ""
#: ../../whatsnew/2.4.rst:256
msgid ""
"The ``@classmethod`` is shorthand for the ``meth=classmethod(meth)`` "
"assignment. More generally, if you have the following::"
msgstr ""
#: ../../whatsnew/2.4.rst:259
msgid ""
"@A\n"
"@B\n"
"@C\n"
"def f ():\n"
" ..."
msgstr ""
#: ../../whatsnew/2.4.rst:265
msgid "It's equivalent to the following pre-decorator code::"
msgstr ""
#: ../../whatsnew/2.4.rst:267
msgid ""
"def f(): ...\n"
"f = A(B(C(f)))"
msgstr ""
#: ../../whatsnew/2.4.rst:270
msgid ""
"Decorators must come on the line before a function definition, one decorator "
"per line, and can't be on the same line as the def statement, meaning that "
"``@A def f(): ...`` is illegal. You can only decorate function definitions, "
"either at the module level or inside a class; you can't decorate class "
"definitions."
msgstr ""
#: ../../whatsnew/2.4.rst:275
msgid ""
"A decorator is just a function that takes the function to be decorated as an "
"argument and returns either the same function or some new object. The "
"return value of the decorator need not be callable (though it typically is), "
"unless further decorators will be applied to the result. It's easy to write "
"your own decorators. The following simple example just sets an attribute on "
"the function object::"
msgstr ""
#: ../../whatsnew/2.4.rst:282
msgid ""
">>> def deco(func):\n"
"... func.attr = 'decorated'\n"
"... return func\n"
"...\n"
">>> @deco\n"
"... def f(): pass\n"
"...\n"
">>> f\n"
"<function f at 0x402ef0d4>\n"
">>> f.attr\n"
"'decorated'\n"
">>>"
msgstr ""
#: ../../whatsnew/2.4.rst:295
msgid ""
"As a slightly more realistic example, the following decorator checks that "
"the supplied argument is an integer::"
msgstr ""
#: ../../whatsnew/2.4.rst:298
msgid ""
"def require_int (func):\n"
" def wrapper (arg):\n"
" assert isinstance(arg, int)\n"
" return func(arg)\n"
"\n"
" return wrapper\n"
"\n"
"@require_int\n"
"def p1 (arg):\n"
" print arg\n"
"\n"
"@require_int\n"
"def p2(arg):\n"
" print arg*2"
msgstr ""
#: ../../whatsnew/2.4.rst:313
msgid ""
"An example in :pep:`318` contains a fancier version of this idea that lets "
"you both specify the required type and check the returned type."
msgstr ""
#: ../../whatsnew/2.4.rst:316
msgid ""
"Decorator functions can take arguments. If arguments are supplied, your "
"decorator function is called with only those arguments and must return a new "
"decorator function; this function must take a single function and return a "
"function, as previously described. In other words, ``@A @B @C(args)`` "
"becomes::"
msgstr ""
#: ../../whatsnew/2.4.rst:321
msgid ""
"def f(): ...\n"
"_deco = C(args)\n"
"f = A(B(_deco(f)))"
msgstr ""
#: ../../whatsnew/2.4.rst:325
msgid ""
"Getting this right can be slightly brain-bending, but it's not too difficult."
msgstr ""
#: ../../whatsnew/2.4.rst:327
msgid ""
"A small related change makes the :attr:`func_name <function.__name__>` "
"attribute of functions writable. This attribute is used to display function "
"names in tracebacks, so decorators should change the name of any new "
"function that's constructed and returned."
msgstr ""
#: ../../whatsnew/2.4.rst:336
msgid ":pep:`318` - Decorators for Functions, Methods and Classes"
msgstr ""
#: ../../whatsnew/2.4.rst:337
msgid ""
"Written by Kevin D. Smith, Jim Jewett, and Skip Montanaro. Several people "
"wrote patches implementing function decorators, but the one that was "
"actually checked in was patch #979728, written by Mark Russell."
msgstr ""
#: ../../whatsnew/2.4.rst:341
msgid "https://wiki.python.org/moin/PythonDecoratorLibrary"
msgstr "https://wiki.python.org/moin/PythonDecoratorLibrary"
#: ../../whatsnew/2.4.rst:342
msgid "This Wiki page contains several examples of decorators."
msgstr ""
#: ../../whatsnew/2.4.rst:348
msgid "PEP 322: Reverse Iteration"
msgstr ""
#: ../../whatsnew/2.4.rst:350
msgid ""
"A new built-in function, ``reversed(seq)``, takes a sequence and returns an "
"iterator that loops over the elements of the sequence in reverse order. ::"
msgstr ""
#: ../../whatsnew/2.4.rst:353
msgid ""
">>> for i in reversed(xrange(1,4)):\n"
"... print i\n"
"...\n"
"3\n"
"2\n"
"1"
msgstr ""
#: ../../whatsnew/2.4.rst:360
msgid ""
"Compared to extended slicing, such as ``range(1,4)[::-1]``, :func:`reversed` "
"is easier to read, runs faster, and uses substantially less memory."
msgstr ""
#: ../../whatsnew/2.4.rst:363
msgid ""
"Note that :func:`reversed` only accepts sequences, not arbitrary iterators. "
"If you want to reverse an iterator, first convert it to a list with :func:"
"`list`. ::"
msgstr ""
#: ../../whatsnew/2.4.rst:367
msgid ""
">>> input = open('/etc/passwd', 'r')\n"
">>> for line in reversed(list(input)):\n"
"... print line\n"
"...\n"
"root:*:0:0:System Administrator:/var/root:/bin/tcsh\n"
" ..."
msgstr ""
">>> input = open('/etc/passwd', 'r')\n"
">>> for line in reversed(list(input)):\n"
"... print line\n"
"...\n"
"root:*:0:0:System Administrator:/var/root:/bin/tcsh\n"
" ..."
#: ../../whatsnew/2.4.rst:377
msgid ":pep:`322` - Reverse Iteration"
msgstr ""
#: ../../whatsnew/2.4.rst:378
msgid "Written and implemented by Raymond Hettinger."
msgstr ""
#: ../../whatsnew/2.4.rst:384
msgid "PEP 324: New subprocess Module"
msgstr ""
#: ../../whatsnew/2.4.rst:386
msgid ""
"The standard library provides a number of ways to execute a subprocess, "
"offering different features and different levels of complexity. ``os."
"system(command)`` is easy to use, but slow (it runs a shell process which "
"executes the command) and dangerous (you have to be careful about escaping "
"the shell's metacharacters). The :mod:`!popen2` module offers classes that "
"can capture standard output and standard error from the subprocess, but the "
"naming is confusing. The :mod:`subprocess` module cleans this up, "
"providing a unified interface that offers all the features you might need."
msgstr ""
#: ../../whatsnew/2.4.rst:395
msgid ""
"Instead of :mod:`!popen2`'s collection of classes, :mod:`subprocess` "
"contains a single class called :class:`subprocess.Popen` whose constructor "
"supports a number of different keyword arguments. ::"
msgstr ""
#: ../../whatsnew/2.4.rst:399
msgid ""
"class Popen(args, bufsize=0, executable=None,\n"
" stdin=None, stdout=None, stderr=None,\n"
" preexec_fn=None, close_fds=False, shell=False,\n"
" cwd=None, env=None, universal_newlines=False,\n"
" startupinfo=None, creationflags=0):"
msgstr ""
#: ../../whatsnew/2.4.rst:405
msgid ""
"*args* is commonly a sequence of strings that will be the arguments to the "
"program executed as the subprocess. (If the *shell* argument is true, "
"*args* can be a string which will then be passed on to the shell for "
"interpretation, just as :func:`os.system` does.)"
msgstr ""
#: ../../whatsnew/2.4.rst:410
msgid ""
"*stdin*, *stdout*, and *stderr* specify what the subprocess's input, output, "
"and error streams will be. You can provide a file object or a file "
"descriptor, or you can use the constant ``subprocess.PIPE`` to create a pipe "
"between the subprocess and the parent."
msgstr ""
#: ../../whatsnew/2.4.rst:418
msgid "The constructor has a number of handy options:"
msgstr ""
#: ../../whatsnew/2.4.rst:420
msgid ""
"*close_fds* requests that all file descriptors be closed before running the "
"subprocess."
msgstr ""
#: ../../whatsnew/2.4.rst:423
msgid ""
"*cwd* specifies the working directory in which the subprocess will be "
"executed (defaulting to whatever the parent's working directory is)."
msgstr ""
#: ../../whatsnew/2.4.rst:426
msgid "*env* is a dictionary specifying environment variables."
msgstr ""
#: ../../whatsnew/2.4.rst:428
msgid ""
"*preexec_fn* is a function that gets called before the child is started."
msgstr ""
#: ../../whatsnew/2.4.rst:430
msgid ""
"*universal_newlines* opens the child's input and output using Python's :term:"
"`universal newlines` feature."
msgstr ""
#: ../../whatsnew/2.4.rst:433
msgid ""
"Once you've created the :class:`Popen` instance, you can call its :meth:"
"`wait` method to pause until the subprocess has exited, :meth:`poll` to "
"check if it's exited without pausing, or ``communicate(data)`` to send the "
"string *data* to the subprocess's standard input. ``communicate(data)`` "
"then reads any data that the subprocess has sent to its standard output or "
"standard error, returning a tuple ``(stdout_data, stderr_data)``."
msgstr ""
#: ../../whatsnew/2.4.rst:440
msgid ""
":func:`call` is a shortcut that passes its arguments along to the :class:"
"`Popen` constructor, waits for the command to complete, and returns the "
"status code of the subprocess. It can serve as a safer analog to :func:`os."
"system`::"
msgstr ""
#: ../../whatsnew/2.4.rst:444
msgid ""
"sts = subprocess.call(['dpkg', '-i', '/tmp/new-package.deb'])\n"
"if sts == 0:\n"
" # Success\n"
" ...\n"
"else:\n"
" # dpkg returned an error\n"
" ..."
msgstr ""
#: ../../whatsnew/2.4.rst:452
msgid ""
"The command is invoked without use of the shell. If you really do want to "
"use the shell, you can add ``shell=True`` as a keyword argument and provide "
"a string instead of a sequence::"
msgstr ""
#: ../../whatsnew/2.4.rst:456
msgid "sts = subprocess.call('dpkg -i /tmp/new-package.deb', shell=True)"
msgstr "sts = subprocess.call('dpkg -i /tmp/new-package.deb', shell=True)"
#: ../../whatsnew/2.4.rst:458
msgid ""
"The PEP takes various examples of shell and Python code and shows how they'd "
"be translated into Python code that uses :mod:`subprocess`. Reading this "
"section of the PEP is highly recommended."
msgstr ""
#: ../../whatsnew/2.4.rst:465
msgid ":pep:`324` - subprocess - New process module"
msgstr ":pep:`324` - subprocess - 新的行程模組"
#: ../../whatsnew/2.4.rst:466
msgid ""
"Written and implemented by Peter Åstrand, with assistance from Fredrik Lundh "
"and others."
msgstr ""
#: ../../whatsnew/2.4.rst:473
msgid "PEP 327: Decimal Data Type"
msgstr ""
#: ../../whatsnew/2.4.rst:475
msgid ""
"Python has always supported floating-point (FP) numbers, based on the "
"underlying C :c:expr:`double` type, as a data type. However, while most "
"programming languages provide a floating-point type, many people (even "
"programmers) are unaware that floating-point numbers don't represent certain "
"decimal fractions accurately. The new :class:`Decimal` type can represent "
"these fractions accurately, up to a user-specified precision limit."
msgstr ""
#: ../../whatsnew/2.4.rst:484
msgid "Why is Decimal needed?"
msgstr ""
#: ../../whatsnew/2.4.rst:486
msgid ""
"The limitations arise from the representation used for floating-point "
"numbers. FP numbers are made up of three components:"
msgstr ""
#: ../../whatsnew/2.4.rst:489
msgid "The sign, which is positive or negative."
msgstr ""
#: ../../whatsnew/2.4.rst:491
msgid ""
"The mantissa, which is a single-digit binary number followed by a "
"fractional part. For example, ``1.01`` in base-2 notation is ``1 + 0/2 + "
"1/4``, or 1.25 in decimal notation."
msgstr ""
#: ../../whatsnew/2.4.rst:495
msgid ""
"The exponent, which tells where the decimal point is located in the number "
"represented."
msgstr ""
#: ../../whatsnew/2.4.rst:498
msgid ""
"For example, the number 1.25 has positive sign, a mantissa value of 1.01 (in "
"binary), and an exponent of 0 (the decimal point doesn't need to be "
"shifted). The number 5 has the same sign and mantissa, but the exponent is 2 "
"because the mantissa is multiplied by 4 (2 to the power of the exponent 2); "
"1.25 \\* 4 equals 5."
msgstr ""
#: ../../whatsnew/2.4.rst:504
msgid ""
"Modern systems usually provide floating-point support that conforms to a "
"standard called IEEE 754. C's :c:expr:`double` type is usually implemented "
"as a 64-bit IEEE 754 number, which uses 52 bits of space for the mantissa. "
"This means that numbers can only be specified to 52 bits of precision. If "
"you're trying to represent numbers whose expansion repeats endlessly, the "
"expansion is cut off after 52 bits. Unfortunately, most software needs to "
"produce output in base 10, and common fractions in base 10 are often "
"repeating decimals in binary. For example, 1.1 decimal is binary "
"``1.0001100110011 ...``; .1 = 1/16 + 1/32 + 1/256 plus an infinite number of "
"additional terms. IEEE 754 has to chop off that infinitely repeated decimal "
"after 52 digits, so the representation is slightly inaccurate."
msgstr ""
#: ../../whatsnew/2.4.rst:516
msgid "Sometimes you can see this inaccuracy when the number is printed::"
msgstr ""
#: ../../whatsnew/2.4.rst:518
msgid ""
">>> 1.1\n"
"1.1000000000000001"
msgstr ""
#: ../../whatsnew/2.4.rst:521
msgid ""
"The inaccuracy isn't always visible when you print the number because the FP-"
"to-decimal-string conversion is provided by the C library, and most C "
"libraries try to produce sensible output. Even if it's not displayed, "
"however, the inaccuracy is still there and subsequent operations can magnify "
"the error."
msgstr ""
#: ../../whatsnew/2.4.rst:526
msgid ""
"For many applications this doesn't matter. If I'm plotting points and "
"displaying them on my monitor, the difference between 1.1 and "
"1.1000000000000001 is too small to be visible. Reports often limit output "
"to a certain number of decimal places, and if you round the number to two or "
"three or even eight decimal places, the error is never apparent. However, "
"for applications where it does matter, it's a lot of work to implement your "
"own custom arithmetic routines."
msgstr ""
#: ../../whatsnew/2.4.rst:534
msgid "Hence, the :class:`Decimal` type was created."
msgstr ""
#: ../../whatsnew/2.4.rst:538
msgid "The :class:`Decimal` type"
msgstr ":class:`Decimal` 型別"
#: ../../whatsnew/2.4.rst:540
msgid ""
"A new module, :mod:`decimal`, was added to Python's standard library. It "
"contains two classes, :class:`Decimal` and :class:`Context`. :class:"
"`Decimal` instances represent numbers, and :class:`Context` instances are "
"used to wrap up various settings such as the precision and default rounding "
"mode."
msgstr ""
#: ../../whatsnew/2.4.rst:545
msgid ""
":class:`Decimal` instances are immutable, like regular Python integers and "
"FP numbers; once it's been created, you can't change the value an instance "
"represents. :class:`Decimal` instances can be created from integers or "
"strings::"
msgstr ""
#: ../../whatsnew/2.4.rst:550
msgid ""
">>> import decimal\n"
">>> decimal.Decimal(1972)\n"
"Decimal(\"1972\")\n"
">>> decimal.Decimal(\"1.1\")\n"
"Decimal(\"1.1\")"
msgstr ""
#: ../../whatsnew/2.4.rst:556
msgid ""
"You can also provide tuples containing the sign, the mantissa represented "
"as a tuple of decimal digits, and the exponent::"
msgstr ""
#: ../../whatsnew/2.4.rst:559
msgid ""
">>> decimal.Decimal((1, (1, 4, 7, 5), -2))\n"
"Decimal(\"-14.75\")"
msgstr ""
#: ../../whatsnew/2.4.rst:562
msgid ""
"Cautionary note: the sign bit is a Boolean value, so 0 is positive and 1 is "
"negative."
msgstr ""
#: ../../whatsnew/2.4.rst:565
msgid ""
"Converting from floating-point numbers poses a bit of a problem: should the "
"FP number representing 1.1 turn into the decimal number for exactly 1.1, or "
"for 1.1 plus whatever inaccuracies are introduced? The decision was to dodge "
"the issue and leave such a conversion out of the API. Instead, you should "
"convert the floating-point number into a string using the desired precision "
"and pass the string to the :class:`Decimal` constructor::"
msgstr ""
#: ../../whatsnew/2.4.rst:572
msgid ""
">>> f = 1.1\n"
">>> decimal.Decimal(str(f))\n"
"Decimal(\"1.1\")\n"
">>> decimal.Decimal('%.12f' % f)\n"
"Decimal(\"1.100000000000\")"
msgstr ""
#: ../../whatsnew/2.4.rst:578
msgid ""
"Once you have :class:`Decimal` instances, you can perform the usual "
"mathematical operations on them. One limitation: exponentiation requires an "
"integer exponent::"
msgstr ""
#: ../../whatsnew/2.4.rst:582
msgid ""
">>> a = decimal.Decimal('35.72')\n"
">>> b = decimal.Decimal('1.73')\n"
">>> a+b\n"
"Decimal(\"37.45\")\n"
">>> a-b\n"
"Decimal(\"33.99\")\n"
">>> a*b\n"
"Decimal(\"61.7956\")\n"
">>> a/b\n"
"Decimal(\"20.64739884393063583815028902\")\n"
">>> a ** 2\n"
"Decimal(\"1275.9184\")\n"
">>> a**b\n"
"Traceback (most recent call last):\n"
" ...\n"
"decimal.InvalidOperation: x ** (non-integer)"
msgstr ""
#: ../../whatsnew/2.4.rst:599
msgid ""
"You can combine :class:`Decimal` instances with integers, but not with "
"floating-point numbers::"
msgstr ""
#: ../../whatsnew/2.4.rst:602
msgid ""
">>> a + 4\n"
"Decimal(\"39.72\")\n"
">>> a + 4.5\n"
"Traceback (most recent call last):\n"
" ...\n"
"TypeError: You can interact Decimal only with int, long or Decimal data "
"types.\n"
">>>"
msgstr ""
#: ../../whatsnew/2.4.rst:610
msgid ""
":class:`Decimal` numbers can be used with the :mod:`math` and :mod:`cmath` "
"modules, but note that they'll be immediately converted to floating-point "
"numbers before the operation is performed, resulting in a possible loss of "
"precision and accuracy. You'll also get back a regular floating-point "
"number and not a :class:`Decimal`. ::"
msgstr ""
#: ../../whatsnew/2.4.rst:616
msgid ""
">>> import math, cmath\n"
">>> d = decimal.Decimal('123456789012.345')\n"
">>> math.sqrt(d)\n"
"351364.18288201344\n"
">>> cmath.sqrt(-d)\n"
"351364.18288201344j"
msgstr ""
#: ../../whatsnew/2.4.rst:623
msgid ""
":class:`Decimal` instances have a :meth:`sqrt` method that returns a :class:"
"`Decimal`, but if you need other things such as trigonometric functions "
"you'll have to implement them. ::"
msgstr ""
#: ../../whatsnew/2.4.rst:627
msgid ""
">>> d.sqrt()\n"
"Decimal(\"351364.1828820134592177245001\")"
msgstr ""
#: ../../whatsnew/2.4.rst:632
msgid "The :class:`Context` type"
msgstr ":class:`Context` 型別"
#: ../../whatsnew/2.4.rst:634
msgid ""
"Instances of the :class:`Context` class encapsulate several settings for "
"decimal operations:"
msgstr ""
#: ../../whatsnew/2.4.rst:637
msgid ":attr:`prec` is the precision, the number of decimal places."
msgstr ""
#: ../../whatsnew/2.4.rst:639
msgid ""
":attr:`rounding` specifies the rounding mode. The :mod:`decimal` module has "
"constants for the various possibilities: :const:`ROUND_DOWN`, :const:"
"`ROUND_CEILING`, :const:`ROUND_HALF_EVEN`, and various others."
msgstr ""
#: ../../whatsnew/2.4.rst:643
msgid ""
":attr:`traps` is a dictionary specifying what happens on encountering "
"certain error conditions: either an exception is raised or a value is "
"returned. Some examples of error conditions are division by zero, loss of "
"precision, and overflow."
msgstr ""
#: ../../whatsnew/2.4.rst:648
msgid ""
"There's a thread-local default context available by calling :func:"
"`getcontext`; you can change the properties of this context to alter the "
"default precision, rounding, or trap handling. The following example shows "
"the effect of changing the precision of the default context::"
msgstr ""
#: ../../whatsnew/2.4.rst:653
msgid ""
">>> decimal.getcontext().prec\n"
"28\n"
">>> decimal.Decimal(1) / decimal.Decimal(7)\n"
"Decimal(\"0.1428571428571428571428571429\")\n"
">>> decimal.getcontext().prec = 9\n"
">>> decimal.Decimal(1) / decimal.Decimal(7)\n"