3
3
# This file is distributed under the same license as the Python package.
4
4
# FIRST AUTHOR <EMAIL@ADDRESS>, 2017.
5
5
#
6
- #, fuzzy
7
6
msgid ""
8
7
msgstr ""
9
8
"Project-Id-Version : Python 3.6\n "
@@ -48,6 +47,9 @@ msgid ""
48
47
">>> reprlib.repr(set('supercalifragilisticexpialidocious'))\n"
49
48
"\" {'a', 'c', 'd', 'e', 'f', 'g', ...}\" "
50
49
msgstr ""
50
+ ">>> import reprlib\n"
51
+ ">>> reprlib.repr(set('supercalifragilisticexpialidocious'))\n"
52
+ "\" {'a', 'c', 'd', 'e', 'f', 'g', ...}\" "
51
53
52
54
#: ../../tutorial/stdlib2.rst:23
53
55
msgid ""
@@ -74,6 +76,16 @@ msgid ""
74
76
" [['magenta', 'yellow'],\n"
75
77
" 'blue']]]"
76
78
msgstr ""
79
+ ">>> import pprint\n"
80
+ ">>> t = [[[['black', 'cyan'], 'white', ['green', 'red']], [['magenta',\n"
81
+ "... 'yellow'], 'blue']]]\n"
82
+ "...\n"
83
+ ">>> pprint.pprint(t, width=30)\n"
84
+ "[[[['black', 'cyan'],\n"
85
+ " 'white',\n"
86
+ " ['green', 'red']],\n"
87
+ " [['magenta', 'yellow'],\n"
88
+ " 'blue']]]"
77
89
78
90
#: ../../tutorial/stdlib2.rst:39
79
91
msgid ""
@@ -96,6 +108,18 @@ msgid ""
96
108
"instead of one big string with newlines\n"
97
109
"to separate the wrapped lines."
98
110
msgstr ""
111
+ ">>> import textwrap\n"
112
+ ">>> doc = \"\"\" The wrap() method is just like fill() except that it "
113
+ "returns\n"
114
+ "... a list of strings instead of one big string with newlines to separate"
115
+ "\n"
116
+ "... the wrapped lines.\"\"\" \n"
117
+ "...\n"
118
+ ">>> print(textwrap.fill(doc, width=40))\n"
119
+ "The wrap() method is just like fill()\n"
120
+ "except that it returns a list of strings\n"
121
+ "instead of one big string with newlines\n"
122
+ "to separate the wrapped lines."
99
123
100
124
#: ../../tutorial/stdlib2.rst:53
101
125
msgid ""
@@ -120,6 +144,16 @@ msgid ""
120
144
"... conv['frac_digits'], x), grouping=True)\n"
121
145
"'$1,234,567.80'"
122
146
msgstr ""
147
+ ">>> import locale\n"
148
+ ">>> locale.setlocale(locale.LC_ALL, 'English_United States.1252')\n"
149
+ "'English_United States.1252'\n"
150
+ ">>> conv = locale.localeconv() # 관례의 매핑을 얻습니다\n"
151
+ ">>> x = 1234567.8\n"
152
+ ">>> locale.format_string(\" %d\" , x, grouping=True)\n"
153
+ "'1,234,567'\n"
154
+ ">>> locale.format_string(\" %s%.*f\" , (conv['currency_symbol'],\n"
155
+ "... conv['frac_digits'], x), grouping=True)\n"
156
+ "'$1,234,567.80'"
123
157
124
158
#: ../../tutorial/stdlib2.rst:72
125
159
msgid "Templating"
@@ -155,6 +189,10 @@ msgid ""
155
189
">>> t.substitute(village='Nottingham', cause='the ditch fund')\n"
156
190
"'Nottinghamfolk send $10 to the ditch fund.'"
157
191
msgstr ""
192
+ ">>> from string import Template\n"
193
+ ">>> t = Template('${village}folk send $$10 to $cause.')\n"
194
+ ">>> t.substitute(village='Nottingham', cause='the ditch fund')\n"
195
+ "'Nottinghamfolk send $10 to the ditch fund.'"
158
196
159
197
#: ../../tutorial/stdlib2.rst:88
160
198
msgid ""
@@ -180,6 +218,14 @@ msgid ""
180
218
">>> t.safe_substitute(d)\n"
181
219
"'Return the unladen swallow to $owner.'"
182
220
msgstr ""
221
+ ">>> t = Template('Return the $item to $owner.')\n"
222
+ ">>> d = dict(item='unladen swallow')\n"
223
+ ">>> t.substitute(d)\n"
224
+ "Traceback (most recent call last):\n"
225
+ " ...\n"
226
+ "KeyError: 'owner'\n"
227
+ ">>> t.safe_substitute(d)\n"
228
+ "'Return the unladen swallow to $owner.'"
183
229
184
230
#: ../../tutorial/stdlib2.rst:103
185
231
msgid ""
@@ -213,6 +259,24 @@ msgid ""
213
259
"img_1076.jpg --> Ashley_1.jpg\n"
214
260
"img_1077.jpg --> Ashley_2.jpg"
215
261
msgstr ""
262
+ ">>> import time, os.path\n"
263
+ ">>> photofiles = ['img_1074.jpg', 'img_1076.jpg', 'img_1077.jpg']\n"
264
+ ">>> class BatchRename(Template):\n"
265
+ "... delimiter = '%'\n"
266
+ "...\n"
267
+ ">>> fmt = input('Enter rename style (%d-date %n-seqnum %f-format): ')\n"
268
+ "Enter rename style (%d-date %n-seqnum %f-format): Ashley_%n%f\n"
269
+ "\n"
270
+ ">>> t = BatchRename(fmt)\n"
271
+ ">>> date = time.strftime('%d%b%y')\n"
272
+ ">>> for i, filename in enumerate(photofiles):\n"
273
+ "... base, ext = os.path.splitext(filename)\n"
274
+ "... newname = t.substitute(d=date, n=i, f=ext)\n"
275
+ "... print('{0} --> {1}'.format(filename, newname))\n"
276
+ "\n"
277
+ "img_1074.jpg --> Ashley_0.jpg\n"
278
+ "img_1076.jpg --> Ashley_1.jpg\n"
279
+ "img_1077.jpg --> Ashley_2.jpg"
216
280
217
281
#: ../../tutorial/stdlib2.rst:126
218
282
msgid ""
@@ -264,6 +328,24 @@ msgid ""
264
328
"\n"
265
329
" start += extra_size + comp_size # skip to the next header"
266
330
msgstr ""
331
+ "import struct\n"
332
+ "\n"
333
+ "with open('myfile.zip', 'rb') as f:\n"
334
+ " data = f.read()\n"
335
+ "\n"
336
+ "start = 0\n"
337
+ "for i in range(3): # 처음 3개의 파일 헤더를 보여줍니다\n"
338
+ " start += 14\n"
339
+ " fields = struct.unpack('<IIIHH', data[start:start+16])\n"
340
+ " crc32, comp_size, uncomp_size, filenamesize, extra_size = fields\n"
341
+ "\n"
342
+ " start += 16\n"
343
+ " filename = data[start:start+filenamesize]\n"
344
+ " start += filenamesize\n"
345
+ " extra = data[start:start+extra_size]\n"
346
+ " print(filename, hex(crc32), comp_size, uncomp_size)\n"
347
+ "\n"
348
+ " start += extra_size + comp_size # 다음 헤더로 건너뜁니다"
267
349
268
350
#: ../../tutorial/stdlib2.rst:167
269
351
msgid "Multi-threading"
@@ -312,6 +394,26 @@ msgid ""
312
394
"background.join() # Wait for the background task to finish\n"
313
395
"print('Main program waited until background was done.')"
314
396
msgstr ""
397
+ "import threading, zipfile\n"
398
+ "\n"
399
+ "class AsyncZip(threading.Thread):\n"
400
+ " def __init__(self, infile, outfile):\n"
401
+ " threading.Thread.__init__(self)\n"
402
+ " self.infile = infile\n"
403
+ " self.outfile = outfile\n"
404
+ "\n"
405
+ " def run(self):\n"
406
+ " f = zipfile.ZipFile(self.outfile, 'w', zipfile.ZIP_DEFLATED)\n"
407
+ " f.write(self.infile)\n"
408
+ " f.close()\n"
409
+ " print('Finished background zip of:', self.infile)\n"
410
+ "\n"
411
+ "background = AsyncZip('mydata.txt', 'myarchive.zip')\n"
412
+ "background.start()\n"
413
+ "print('The main program continues to run in foreground.')\n"
414
+ "\n"
415
+ "background.join() # 백그라운드 작업이 끝날 때까지 기다립니다\n"
416
+ "print('Main program waited until background was done.')"
315
417
316
418
#: ../../tutorial/stdlib2.rst:198
317
419
msgid ""
@@ -361,6 +463,12 @@ msgid ""
361
463
"logging.error('Error occurred')\n"
362
464
"logging.critical('Critical error -- shutting down')"
363
465
msgstr ""
466
+ "import logging\n"
467
+ "logging.debug('Debugging information')\n"
468
+ "logging.info('Informational message')\n"
469
+ "logging.warning('Warning:config file %s not found', 'server.conf')\n"
470
+ "logging.error('Error occurred')\n"
471
+ "logging.critical('Critical error -- shutting down')"
364
472
365
473
#: ../../tutorial/stdlib2.rst:226
366
474
msgid "This produces the following output:"
@@ -372,6 +480,9 @@ msgid ""
372
480
"ERROR:root:Error occurred\n"
373
481
"CRITICAL:root:Critical error -- shutting down"
374
482
msgstr ""
483
+ "WARNING:root:Warning:config file server.conf not found\n"
484
+ "ERROR:root:Error occurred\n"
485
+ "CRITICAL:root:Critical error -- shutting down"
375
486
376
487
#: ../../tutorial/stdlib2.rst:234
377
488
msgid ""
@@ -453,6 +564,28 @@ msgid ""
453
564
" o = self.data[key]()\n"
454
565
"KeyError: 'primary'"
455
566
msgstr ""
567
+ ">>> import weakref, gc\n"
568
+ ">>> class A:\n"
569
+ "... def __init__(self, value):\n"
570
+ "... self.value = value\n"
571
+ "... def __repr__(self):\n"
572
+ "... return str(self.value)\n"
573
+ "...\n"
574
+ ">>> a = A(10) # 참조를 만듭니다\n"
575
+ ">>> d = weakref.WeakValueDictionary()\n"
576
+ ">>> d['primary'] = a # 참조를 만들지 않습니다\n"
577
+ ">>> d['primary'] # 객체가 아직 살아있다면 가져옵니다\n"
578
+ "10\n"
579
+ ">>> del a # 참조 하나를 지웁니다\n"
580
+ ">>> gc.collect() # 당장 가비지 수집을 실행합니다\n"
581
+ "0\n"
582
+ ">>> d['primary'] # 항목이 저절로 삭제되었습니다\n"
583
+ "Traceback (most recent call last):\n"
584
+ " File \" <stdin>\" , line 1, in <module>\n"
585
+ " d['primary'] # 항목이 저절로 삭제되었습니다\n"
586
+ " File \" C:/python313/lib/weakref.py\" , line 46, in __getitem__\n"
587
+ " o = self.data[key]()\n"
588
+ "KeyError: 'primary'"
456
589
457
590
#: ../../tutorial/stdlib2.rst:290
458
591
msgid "Tools for Working with Lists"
@@ -468,16 +601,15 @@ msgstr ""
468
601
" 수도 있습니다."
469
602
470
603
#: ../../tutorial/stdlib2.rst:296
471
- #, fuzzy
472
604
msgid ""
473
605
"The :mod:`array` module provides an :class:`~array.array` object that is "
474
606
"like a list that stores only homogeneous data and stores it more "
475
607
"compactly. The following example shows an array of numbers stored as two"
476
608
" byte unsigned binary numbers (typecode ``\" H\" ``) rather than the usual "
477
609
"16 bytes per entry for regular lists of Python int objects::"
478
610
msgstr ""
479
- ":mod:`array` 모듈은 :class:`~array.array() ` 객체를 제공합니다. 이 객체는 등질적인 데이터만을 저장하고"
480
- " 보다 조밀하게 저장하는 리스트와 같습니다. 다음 예제는 파이썬 int 객체의 일반 리스트의 경우처럼 항목당 16바이트를 사용하는 "
611
+ ":mod:`array` 모듈은 :class:`~array.array` 객체를 제공합니다. 이 객체는 등질적인 데이터만을 저장하고 "
612
+ "보다 조밀하게 저장하는 리스트와 같습니다. 다음 예제는 파이썬 int 객체의 일반 리스트의 경우처럼 항목당 16바이트를 사용하는 "
481
613
"대신에, 2바이트의 부호 없는 이진 숫자 (형 코드 ``\" H\" ``)로 저장된 숫자 배열을 보여줍니다::"
482
614
483
615
#: ../../tutorial/stdlib2.rst:302
@@ -489,18 +621,23 @@ msgid ""
489
621
">>> a[1:3]\n"
490
622
"array('H', [10, 700])"
491
623
msgstr ""
624
+ ">>> from array import array\n"
625
+ ">>> a = array('H', [4000, 10, 700, 22222])\n"
626
+ ">>> sum(a)\n"
627
+ "26932\n"
628
+ ">>> a[1:3]\n"
629
+ "array('H', [10, 700])"
492
630
493
631
#: ../../tutorial/stdlib2.rst:309
494
- #, fuzzy
495
632
msgid ""
496
633
"The :mod:`collections` module provides a :class:`~collections.deque` "
497
634
"object that is like a list with faster appends and pops from the left "
498
635
"side but slower lookups in the middle. These objects are well suited for "
499
636
"implementing queues and breadth first tree searches::"
500
637
msgstr ""
501
- ":mod:`collections` 모듈은 :class:`~collections.deque() ` 객체를 제공합니다. 이 객체는 "
502
- "왼쪽에서 더 빠르게 추가/팝하지만 중간에서의 조회는 더 느려진 리스트와 같습니다. 이 객체는 대기열 및 넓이 우선 트리 검색을 "
503
- "구현하는 데 적합합니다::"
638
+ ":mod:`collections` 모듈은 :class:`~collections.deque` 객체를 제공합니다. 이 객체는 왼쪽에서 "
639
+ "더 빠르게 추가/팝하지만 중간에서의 조회는 더 느려진 리스트와 같습니다. 이 객체는 대기열 및 넓이 우선 트리 검색을 구현하는 데 "
640
+ "적합합니다::"
504
641
505
642
#: ../../tutorial/stdlib2.rst:314
506
643
msgid ""
@@ -510,6 +647,11 @@ msgid ""
510
647
">>> print(\" Handling\" , d.popleft())\n"
511
648
"Handling task1"
512
649
msgstr ""
650
+ ">>> from collections import deque\n"
651
+ ">>> d = deque([\" task1\" , \" task2\" , \" task3\" ])\n"
652
+ ">>> d.append(\" task4\" )\n"
653
+ ">>> print(\" Handling\" , d.popleft())\n"
654
+ "Handling task1"
513
655
514
656
#: ../../tutorial/stdlib2.rst:322
515
657
msgid ""
@@ -521,6 +663,13 @@ msgid ""
521
663
" return m\n"
522
664
" unsearched.append(m)"
523
665
msgstr ""
666
+ "unsearched = deque([starting_node])\n"
667
+ "def breadth_first_search(unsearched):\n"
668
+ " node = unsearched.popleft()\n"
669
+ " for m in gen_moves(node):\n"
670
+ " if is_goal(m):\n"
671
+ " return m\n"
672
+ " unsearched.append(m)"
524
673
525
674
#: ../../tutorial/stdlib2.rst:330
526
675
msgid ""
@@ -541,6 +690,13 @@ msgid ""
541
690
"[(100, 'perl'), (200, 'tcl'), (300, 'ruby'), (400, 'lua'), (500, "
542
691
"'python')]"
543
692
msgstr ""
693
+ ">>> import bisect\n"
694
+ ">>> scores = [(100, 'perl'), (200, 'tcl'), (400, 'lua'), (500, 'python')]"
695
+ "\n"
696
+ ">>> bisect.insort(scores, (300, 'ruby'))\n"
697
+ ">>> scores\n"
698
+ "[(100, 'perl'), (200, 'tcl'), (300, 'ruby'), (400, 'lua'), (500, "
699
+ "'python')]"
544
700
545
701
#: ../../tutorial/stdlib2.rst:340
546
702
msgid ""
@@ -563,14 +719,18 @@ msgid ""
563
719
"\n"
564
720
"[-5, 0, 1]"
565
721
msgstr ""
722
+ ">>> from heapq import heapify, heappop, heappush\n"
723
+ ">>> data = [1, 3, 5, 7, 9, 2, 4, 6, 8, 0]\n"
724
+ ">>> heapify(data) # 리스트를 힙 순서로 재배치합니다\n"
725
+ ">>> heappush(data, -5) # 새 항목을 추가합니다\n"
726
+ ">>> [heappop(data) for i in range(3)] # 가장 작은 세 개의 항목을 가져옵니다\n"
727
+ "[-5, 0, 1]"
566
728
567
729
#: ../../tutorial/stdlib2.rst:356
568
- #, fuzzy
569
730
msgid "Decimal Floating-Point Arithmetic"
570
731
msgstr "10진 부동 소수점 산술"
571
732
572
733
#: ../../tutorial/stdlib2.rst:358
573
- #, fuzzy
574
734
msgid ""
575
735
"The :mod:`decimal` module offers a :class:`~decimal.Decimal` datatype for"
576
736
" decimal floating-point arithmetic. Compared to the built-in "
@@ -622,6 +782,11 @@ msgid ""
622
782
">>> round(.70 * 1.05, 2)\n"
623
783
"0.73"
624
784
msgstr ""
785
+ ">>> from decimal import *\n"
786
+ ">>> round(Decimal('0.70') * Decimal('1.05'), 2)\n"
787
+ "Decimal('0.74')\n"
788
+ ">>> round(.70 * 1.05, 2)\n"
789
+ "0.73"
625
790
626
791
#: ../../tutorial/stdlib2.rst:380
627
792
msgid ""
@@ -656,6 +821,15 @@ msgid ""
656
821
">>> 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 == 1.0\n"
657
822
"False"
658
823
msgstr ""
824
+ ">>> Decimal('1.00') % Decimal('.10')\n"
825
+ "Decimal('0.00')\n"
826
+ ">>> 1.00 % 0.10\n"
827
+ "0.09999999999999995\n"
828
+ "\n"
829
+ ">>> sum([Decimal('0.1')]*10) == Decimal('1.0')\n"
830
+ "True\n"
831
+ ">>> 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 == 1.0\n"
832
+ "False"
659
833
660
834
#: ../../tutorial/stdlib2.rst:400
661
835
msgid ""
@@ -669,4 +843,7 @@ msgid ""
669
843
">>> Decimal(1) / Decimal(7)\n"
670
844
"Decimal('0.142857142857142857142857142857142857')"
671
845
msgstr ""
846
+ ">>> getcontext().prec = 36\n"
847
+ ">>> Decimal(1) / Decimal(7)\n"
848
+ "Decimal('0.142857142857142857142857142857142857')"
672
849
0 commit comments