@@ -40,6 +40,13 @@ msgid ""
40
40
"shell\n"
41
41
"0"
42
42
msgstr ""
43
+ ">>> import os\n"
44
+ ">>> os.getcwd() # 현재 작업 디렉터리를 돌려줍니다\n"
45
+ "'C:\\\\ Python313'\n"
46
+ ">>> os.chdir('/server/accesslogs') # Change current working directory\n"
47
+ ">>> os.system('mkdir today') # Run the command mkdir in the system "
48
+ "shell\n"
49
+ "0"
43
50
44
51
#: ../../tutorial/stdlib.rst:23
45
52
msgid ""
@@ -66,6 +73,11 @@ msgid ""
66
73
">>> help(os)\n"
67
74
"<returns an extensive manual page created from the module's docstrings>"
68
75
msgstr ""
76
+ ">>> import os\n"
77
+ ">>> dir(os)\n"
78
+ "<returns a list of all module functions>\n"
79
+ ">>> help(os)\n"
80
+ "<returns an extensive manual page created from the module's docstrings>"
69
81
70
82
#: ../../tutorial/stdlib.rst:38
71
83
msgid ""
@@ -81,6 +93,11 @@ msgid ""
81
93
">>> shutil.move('/build/executables', 'installdir')\n"
82
94
"'installdir'"
83
95
msgstr ""
96
+ ">>> import shutil\n"
97
+ ">>> shutil.copyfile('data.db', 'archive.db')\n"
98
+ "'archive.db'\n"
99
+ ">>> shutil.move('/build/executables', 'installdir')\n"
100
+ "'installdir'"
84
101
85
102
#: ../../tutorial/stdlib.rst:51
86
103
msgid "File Wildcards"
@@ -98,38 +115,42 @@ msgid ""
98
115
">>> glob.glob('*.py')\n"
99
116
"['primes.py', 'random.py', 'quote.py']"
100
117
msgstr ""
118
+ ">>> import glob\n"
119
+ ">>> glob.glob('*.py')\n"
120
+ "['primes.py', 'random.py', 'quote.py']"
101
121
102
122
#: ../../tutorial/stdlib.rst:64
103
123
msgid "Command Line Arguments"
104
124
msgstr "명령행 인자"
105
125
106
126
#: ../../tutorial/stdlib.rst:66
107
- #, fuzzy
108
127
msgid ""
109
128
"Common utility scripts often need to process command line arguments. "
110
129
"These arguments are stored in the :mod:`sys` module's *argv* attribute as"
111
130
" a list. For instance, let's take the following :file:`demo.py` file::"
112
131
msgstr ""
113
132
"일반적인 유틸리티 스크립트는 종종 명령행 인자를 처리해야 할 필요가 있습니다. 이 인자들은 :mod:`sys` 모듈의 *argv* "
114
- "어트리뷰트에 리스트로 저장됩니다. 예를 들어, 명령행에서 ``python demo.py one two three`` 를 실행하면 "
115
- "다음과 같은 결과가 출력됩니다::"
133
+ "어트리뷰트에 리스트로 저장됩니다. 예를 들어, 다음과 같은 :file:`demo.py` 파일을 보겠습니다::"
116
134
117
135
#: ../../tutorial/stdlib.rst:70
118
136
msgid ""
119
137
"# File demo.py\n"
120
138
"import sys\n"
121
139
"print(sys.argv)"
122
140
msgstr ""
141
+ "# 파일 demo.py\n"
142
+ "import sys\n"
143
+ "print(sys.argv)"
123
144
124
145
#: ../../tutorial/stdlib.rst:74
125
146
msgid ""
126
147
"Here is the output from running ``python demo.py one two three`` at the "
127
148
"command line::"
128
- msgstr ""
149
+ msgstr "다음은 명령행에서 ``python demo.py one two three`` 를 실행한 출력입니다:: "
129
150
130
151
#: ../../tutorial/stdlib.rst:77
131
152
msgid "['demo.py', 'one', 'two', 'three']"
132
- msgstr ""
153
+ msgstr "['demo.py', 'one', 'two', 'three'] "
133
154
134
155
#: ../../tutorial/stdlib.rst:79
135
156
msgid ""
@@ -152,6 +173,15 @@ msgid ""
152
173
"args = parser.parse_args()\n"
153
174
"print(args)"
154
175
msgstr ""
176
+ "import argparse\n"
177
+ "\n"
178
+ "parser = argparse.ArgumentParser(\n"
179
+ " prog='top',\n"
180
+ " description='Show top lines from each file')\n"
181
+ "parser.add_argument('filenames', nargs='+')\n"
182
+ "parser.add_argument('-l', '--lines', type=int, default=10)\n"
183
+ "args = parser.parse_args()\n"
184
+ "print(args)"
155
185
156
186
#: ../../tutorial/stdlib.rst:93
157
187
msgid ""
@@ -182,6 +212,9 @@ msgid ""
182
212
"\n"
183
213
"Warning, log file not found starting a new one"
184
214
msgstr ""
215
+ ">>> sys.stderr.write('Warning, log file not found starting a new one\\ n')"
216
+ "\n"
217
+ "Warning, log file not found starting a new one"
185
218
186
219
#: ../../tutorial/stdlib.rst:110
187
220
msgid "The most direct way to terminate a script is to use ``sys.exit()``."
@@ -208,6 +241,11 @@ msgid ""
208
241
">>> re.sub(r'(\\ b[a-z]+) \\ 1', r'\\ 1', 'cat in the the hat')\n"
209
242
"'cat in the hat'"
210
243
msgstr ""
244
+ ">>> import re\n"
245
+ ">>> re.findall(r'\\ bf[a-z]*', 'which foot or hand fell fastest')\n"
246
+ "['foot', 'fell', 'fastest']\n"
247
+ ">>> re.sub(r'(\\ b[a-z]+) \\ 1', r'\\ 1', 'cat in the the hat')\n"
248
+ "'cat in the hat'"
211
249
212
250
#: ../../tutorial/stdlib.rst:128
213
251
msgid ""
@@ -220,13 +258,14 @@ msgid ""
220
258
">>> 'tea for too'.replace('too', 'two')\n"
221
259
"'tea for two'"
222
260
msgstr ""
261
+ ">>> 'tea for too'.replace('too', 'two')\n"
262
+ "'tea for two'"
223
263
224
264
#: ../../tutorial/stdlib.rst:138
225
265
msgid "Mathematics"
226
266
msgstr "수학"
227
267
228
268
#: ../../tutorial/stdlib.rst:140
229
- #, fuzzy
230
269
msgid ""
231
270
"The :mod:`math` module gives access to the underlying C library functions"
232
271
" for floating-point math::"
@@ -240,6 +279,11 @@ msgid ""
240
279
">>> math.log(1024, 2)\n"
241
280
"10.0"
242
281
msgstr ""
282
+ ">>> import math\n"
283
+ ">>> math.cos(math.pi / 4)\n"
284
+ "0.70710678118654757\n"
285
+ ">>> math.log(1024, 2)\n"
286
+ "10.0"
243
287
244
288
#: ../../tutorial/stdlib.rst:149
245
289
msgid "The :mod:`random` module provides tools for making random selections::"
@@ -257,6 +301,15 @@ msgid ""
257
301
">>> random.randrange(6) # random integer chosen from range(6)\n"
258
302
"4"
259
303
msgstr ""
304
+ ">>> import random\n"
305
+ ">>> random.choice(['apple', 'pear', 'banana'])\n"
306
+ "'apple'\n"
307
+ ">>> random.sample(range(100), 10) # 대체 없는 표본 추출\n"
308
+ "[30, 83, 16, 4, 8, 81, 41, 50, 18, 33]\n"
309
+ ">>> random.random() # 범위 [0.0, 1.0) 내에서의 임의의 float\n"
310
+ "0.17970987693706186\n"
311
+ ">>> random.randrange(6) # range(6) 에서 선택된 임의의 정수\n"
312
+ "4"
260
313
261
314
#: ../../tutorial/stdlib.rst:161
262
315
msgid ""
@@ -275,6 +328,14 @@ msgid ""
275
328
">>> statistics.variance(data)\n"
276
329
"1.3720238095238095"
277
330
msgstr ""
331
+ ">>> import statistics\n"
332
+ ">>> data = [2.75, 1.75, 1.25, 0.25, 0.5, 1.25, 3.5]\n"
333
+ ">>> statistics.mean(data)\n"
334
+ "1.6071428571428572\n"
335
+ ">>> statistics.median(data)\n"
336
+ "1.25\n"
337
+ ">>> statistics.variance(data)\n"
338
+ "1.3720238095238095"
278
339
279
340
#: ../../tutorial/stdlib.rst:173
280
341
msgid ""
@@ -317,6 +378,25 @@ msgid ""
317
378
"... \"\"\" )\n"
318
379
">>> server.quit()"
319
380
msgstr ""
381
+ ">>> from urllib.request import urlopen\n"
382
+ ">>> with urlopen('http://worldtimeapi.org/api/timezone/etc/UTC.txt') as "
383
+ "response:\n"
384
+ "... for line in response:\n"
385
+ "... line = line.decode() # bytes 를 str 로 변환합니다\n"
386
+ "... if line.startswith('datetime'):\n"
387
+ "... print(line.rstrip()) # 후행 줄 넘김을 제거합니다\n"
388
+ "...\n"
389
+ "datetime: 2022-01-01T01:36:47.689215+00:00\n"
390
+ "\n"
391
+ ">>> import smtplib\n"
392
+ ">>> server = smtplib.SMTP('localhost')\n"
393
+
394
+ "... \"\"\" To: [email protected] \n"
395
+
396
+ "...\n"
397
+ "... Beware the Ides of March.\n"
398
+ "... \"\"\" )\n"
399
+ ">>> server.quit()"
320
400
321
401
#: ../../tutorial/stdlib.rst:204
322
402
msgid "(Note that the second example needs a mailserver running on localhost.)"
@@ -355,6 +435,19 @@ msgid ""
355
435
">>> age.days\n"
356
436
"14368"
357
437
msgstr ""
438
+ ">>> # 날짜는 쉽게 구성되고 포맷됩니다\n"
439
+ ">>> from datetime import date\n"
440
+ ">>> now = date.today()\n"
441
+ ">>> now\n"
442
+ "datetime.date(2003, 12, 2)\n"
443
+ ">>> now.strftime(\" %m-%d-%y. %d %b %Y is a %A on the %d day of %B.\" )\n"
444
+ "'12-02-03. 02 Dec 2003 is a Tuesday on the 02 day of December.'\n"
445
+ "\n"
446
+ ">>> # 날짜는 캘린더 산술을 지원합니다\n"
447
+ ">>> birthday = date(1964, 7, 31)\n"
448
+ ">>> age = now - birthday\n"
449
+ ">>> age.days\n"
450
+ "14368"
358
451
359
452
#: ../../tutorial/stdlib.rst:236
360
453
msgid "Data Compression"
@@ -383,6 +476,17 @@ msgid ""
383
476
">>> zlib.crc32(s)\n"
384
477
"226805979"
385
478
msgstr ""
479
+ ">>> import zlib\n"
480
+ ">>> s = b'witch which has which witches wrist watch'\n"
481
+ ">>> len(s)\n"
482
+ "41\n"
483
+ ">>> t = zlib.compress(s)\n"
484
+ ">>> len(t)\n"
485
+ "37\n"
486
+ ">>> zlib.decompress(t)\n"
487
+ "b'witch which has which witches wrist watch'\n"
488
+ ">>> zlib.crc32(s)\n"
489
+ "226805979"
386
490
387
491
#: ../../tutorial/stdlib.rst:258
388
492
msgid "Performance Measurement"
@@ -415,6 +519,11 @@ msgid ""
415
519
">>> Timer('a,b = b,a', 'a=1; b=2').timeit()\n"
416
520
"0.54962537085770791"
417
521
msgstr ""
522
+ ">>> from timeit import Timer\n"
523
+ ">>> Timer('t=a; a=b; b=t', 'a=1; b=2').timeit()\n"
524
+ "0.57535828626024577\n"
525
+ ">>> Timer('a,b = b,a', 'a=1; b=2').timeit()\n"
526
+ "0.54962537085770791"
418
527
419
528
#: ../../tutorial/stdlib.rst:274
420
529
msgid ""
@@ -464,6 +573,16 @@ msgid ""
464
573
"import doctest\n"
465
574
"doctest.testmod() # automatically validate the embedded tests"
466
575
msgstr ""
576
+ "def average(values):\n"
577
+ " \"\"\" 숫자 목록의 산술 평균을 계산합니다.\n"
578
+ "\n"
579
+ " >>> print(average([20, 30, 70]))\n"
580
+ " 40.0\n"
581
+ " \"\"\" \n"
582
+ " return sum(values) / len(values)\n"
583
+ "\n"
584
+ "import doctest\n"
585
+ "doctest.testmod() # 내장된 테스트를 자동 검증합니다"
467
586
468
587
#: ../../tutorial/stdlib.rst:306
469
588
msgid ""
@@ -490,6 +609,19 @@ msgid ""
490
609
"\n"
491
610
"unittest.main() # Calling from the command line invokes all tests"
492
611
msgstr ""
612
+ "import unittest\n"
613
+ "\n"
614
+ "class TestStatisticalFunctions(unittest.TestCase):\n"
615
+ "\n"
616
+ " def test_average(self):\n"
617
+ " self.assertEqual(average([20, 30, 70]), 40.0)\n"
618
+ " self.assertEqual(round(average([1, 5, 7]), 1), 4.3)\n"
619
+ " with self.assertRaises(ZeroDivisionError):\n"
620
+ " average([])\n"
621
+ " with self.assertRaises(TypeError):\n"
622
+ " average(20, 30, 70)\n"
623
+ "\n"
624
+ "unittest.main() # 명령행에서 호출하면 모든 테스트를 수행합니다"
493
625
494
626
#: ../../tutorial/stdlib.rst:328
495
627
msgid "Batteries Included"
@@ -505,7 +637,6 @@ msgstr ""
505
637
"예를 들어:"
506
638
507
639
#: ../../tutorial/stdlib.rst:333
508
- #, fuzzy
509
640
msgid ""
510
641
"The :mod:`xmlrpc.client` and :mod:`xmlrpc.server` modules make "
511
642
"implementing remote procedure calls into an almost trivial task. Despite"
@@ -562,9 +693,9 @@ msgstr ""
562
693
563
694
#: ../../tutorial/stdlib.rst:27
564
695
msgid "built-in function"
565
- msgstr ""
696
+ msgstr "내장 함수 "
566
697
567
698
#: ../../tutorial/stdlib.rst:27
568
699
msgid "help"
569
- msgstr ""
700
+ msgstr "도움말 "
570
701
0 commit comments