-
-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathlibrary.po
959 lines (819 loc) · 45.5 KB
/
library.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
# SOME DESCRIPTIVE TITLE.
# Copyright (C) 2001-2022, Python Software Foundation
# This file is distributed under the same license as the Python package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
# Translators:
# cissoid <yangtukun1412@gmail.com>, 2018
# ppcfish <ppcfish@gmail.com>, 2019
# Freesand Leo <yuqinju@163.com>, 2021
# Alpha Du <alphanow@gmail.com>, 2022
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: Python 3.9\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-11-04 14:34+0000\n"
"PO-Revision-Date: 2017-02-16 17:43+0000\n"
"Last-Translator: Alpha Du <alphanow@gmail.com>, 2022\n"
"Language-Team: Chinese (China) (https://www.transifex.com/python-doc/teams/5390/zh_CN/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: zh_CN\n"
"Plural-Forms: nplurals=1; plural=0;\n"
#: ../../faq/library.rst:5
msgid "Library and Extension FAQ"
msgstr "代码库和插件 FAQ"
#: ../../faq/library.rst:8
msgid "Contents"
msgstr "目录"
#: ../../faq/library.rst:12
msgid "General Library Questions"
msgstr "通用的代码库问题"
#: ../../faq/library.rst:15
msgid "How do I find a module or application to perform task X?"
msgstr "如何找到可以用来做 XXX 的模块或应用?"
#: ../../faq/library.rst:17
msgid ""
"Check :ref:`the Library Reference <library-index>` to see if there's a "
"relevant standard library module. (Eventually you'll learn what's in the "
"standard library and will be able to skip this step.)"
msgstr "在 :ref:`代码库参考 <library-index>` 中查找是否有适合的标准库模块。(如果你已经了解标准库的内容,可以跳过这一步)"
#: ../../faq/library.rst:21
msgid ""
"For third-party packages, search the `Python Package Index "
"<https://pypi.org>`_ or try `Google <https://www.google.com>`_ or another "
"Web search engine. Searching for \"Python\" plus a keyword or two for your "
"topic of interest will usually find something helpful."
msgstr ""
"对于第三方软件包,请搜索 `Python Package Index <https://pypi.org>`_ 或是 `Google "
"<https://www.google.com>`_ 等其他搜索引擎。用“Python”加上一两个你需要的关键字通常会找到有用的东西。"
#: ../../faq/library.rst:28
msgid "Where is the math.py (socket.py, regex.py, etc.) source file?"
msgstr "math.py(socket.py,regex.py 等)的源文件在哪?"
#: ../../faq/library.rst:30
msgid ""
"If you can't find a source file for a module it may be a built-in or "
"dynamically loaded module implemented in C, C++ or other compiled language. "
"In this case you may not have the source file or it may be something like "
":file:`mathmodule.c`, somewhere in a C source directory (not on the Python "
"Path)."
msgstr ""
"如果找不到模块的源文件,可能它是一个内建的模块,或是使用 C,C++ 或其他编译型语言实现的动态加载模块。这种情况下可能是没有源码文件的,类似 "
":file:`mathmodule.c` 这样的文件会存放在 C 代码目录中(但不在 Python 目录中)。"
#: ../../faq/library.rst:35
msgid "There are (at least) three kinds of modules in Python:"
msgstr "Python 中(至少)有三类模块:"
#: ../../faq/library.rst:37
msgid "modules written in Python (.py);"
msgstr "使用 Python 编写的模块(.py);"
#: ../../faq/library.rst:38
msgid ""
"modules written in C and dynamically loaded (.dll, .pyd, .so, .sl, etc);"
msgstr "使用 C 编写的动态加载模块(.dll,.pyd,.so,.sl 等);"
#: ../../faq/library.rst:39
msgid ""
"modules written in C and linked with the interpreter; to get a list of "
"these, type::"
msgstr "使用 C 编写并链接到解释器的模块,要获取此列表,输入:"
#: ../../faq/library.rst:47
msgid "How do I make a Python script executable on Unix?"
msgstr "在 Unix 中怎样让 Python 脚本可执行?"
#: ../../faq/library.rst:49
msgid ""
"You need to do two things: the script file's mode must be executable and the"
" first line must begin with ``#!`` followed by the path of the Python "
"interpreter."
msgstr "你需要做两件事:文件必须是可执行的,并且第一行需要以 ``#!`` 开头,后面跟上 Python 解释器的路径。"
#: ../../faq/library.rst:53
msgid ""
"The first is done by executing ``chmod +x scriptfile`` or perhaps ``chmod "
"755 scriptfile``."
msgstr "第一点可以用执行 ``chmod +x scriptfile`` 或是 ``chmod 755 scriptfile`` 做到。"
#: ../../faq/library.rst:56
msgid ""
"The second can be done in a number of ways. The most straightforward way is"
" to write ::"
msgstr "第二点有很多种做法,最直接的方式是:"
#: ../../faq/library.rst:61
msgid ""
"as the very first line of your file, using the pathname for where the Python"
" interpreter is installed on your platform."
msgstr "在文件第一行,使用你所在平台上的 Python 解释器的路径。"
#: ../../faq/library.rst:64
msgid ""
"If you would like the script to be independent of where the Python "
"interpreter lives, you can use the :program:`env` program. Almost all Unix "
"variants support the following, assuming the Python interpreter is in a "
"directory on the user's :envvar:`PATH`::"
msgstr ""
"如果你希望脚本不依赖 Python 解释器的具体路径,你也可以使用 :program:`env` 程序。假设你的 Python "
"解释器所在目录已经添加到了 :envvar:`PATH` 环境变量中,几乎所有的类 Unix 系统都支持下面的写法:"
#: ../../faq/library.rst:71
msgid ""
"*Don't* do this for CGI scripts. The :envvar:`PATH` variable for CGI "
"scripts is often very minimal, so you need to use the actual absolute "
"pathname of the interpreter."
msgstr ""
"*不要* 在 CGI 脚本中这样做。CGI 脚本的 :envvar:`PATH` 环境变量通常会非常精简,所以你必须使用解释器的完整绝对路径。"
#: ../../faq/library.rst:75
msgid ""
"Occasionally, a user's environment is so full that the "
":program:`/usr/bin/env` program fails; or there's no env program at all. In"
" that case, you can try the following hack (due to Alex Rezinsky):"
msgstr ""
"有时候,用户的环境变量如果太长,可能会导致 :program:`/usr/bin/env` 执行失败;又或者甚至根本就不存在 env "
"程序。在这种情况下,你可以尝试使用下面的 hack 方法(来自 Alex Rezinsky):"
#: ../../faq/library.rst:86
msgid ""
"The minor disadvantage is that this defines the script's __doc__ string. "
"However, you can fix that by adding ::"
msgstr "这样做有一个小小的缺点,它会定义脚本的 __doc__ 字符串。不过可以这样修复:"
#: ../../faq/library.rst:94
msgid "Is there a curses/termcap package for Python?"
msgstr "Python 中有 curses/termcap 包吗?"
#: ../../faq/library.rst:98
msgid ""
"For Unix variants: The standard Python source distribution comes with a "
"curses module in the :source:`Modules` subdirectory, though it's not "
"compiled by default. (Note that this is not available in the Windows "
"distribution -- there is no curses module for Windows.)"
msgstr ""
"对于类 Unix 系统:标准 Python 源码发行版会在 :source:`Modules` 子目录中附带 curses "
"模块,但默认并不会编译。(注意:在 Windows 平台下不可用 —— Windows 中没有 curses 模块。)"
#: ../../faq/library.rst:103
msgid ""
"The :mod:`curses` module supports basic curses features as well as many "
"additional functions from ncurses and SYSV curses such as colour, "
"alternative character set support, pads, and mouse support. This means the "
"module isn't compatible with operating systems that only have BSD curses, "
"but there don't seem to be any currently maintained OSes that fall into this"
" category."
msgstr ""
":mod:`curses` 模块支持基本的 curses 特性,同时也支持 ncurses 和 SYSV curses "
"中的很多额外功能,比如颜色、不同的字符集支持、填充和鼠标支持。这意味着这个模块不兼容只有 BSD curses "
"模块的操作系统,但是目前仍在维护的系统应该都不会存在这种情况。"
#: ../../faq/library.rst:111
msgid "Is there an equivalent to C's onexit() in Python?"
msgstr "Python 中存在类似 C 的 onexit() 函数的东西吗?"
#: ../../faq/library.rst:113
msgid ""
"The :mod:`atexit` module provides a register function that is similar to C's"
" :c:func:`onexit`."
msgstr ":mod:`atexit` 模块提供了一个与 C 的 :c:func:`onexit` 函数类似的注册函数。"
#: ../../faq/library.rst:118
msgid "Why don't my signal handlers work?"
msgstr "为什么我的信号处理函数不能工作?"
#: ../../faq/library.rst:120
msgid ""
"The most common problem is that the signal handler is declared with the "
"wrong argument list. It is called as ::"
msgstr "最常见的问题是信号处理函数没有正确定义参数列表。它会被这样调用:"
#: ../../faq/library.rst:125
msgid "so it should be declared with two parameters::"
msgstr "因此它应当声明为带有两个形参::"
#: ../../faq/library.rst:132
msgid "Common tasks"
msgstr "通用任务"
#: ../../faq/library.rst:135
msgid "How do I test a Python program or component?"
msgstr "怎样测试 Python 程序或组件?"
#: ../../faq/library.rst:137
msgid ""
"Python comes with two testing frameworks. The :mod:`doctest` module finds "
"examples in the docstrings for a module and runs them, comparing the output "
"with the expected output given in the docstring."
msgstr ""
"Python 带有两个测试框架。:mod:`doctest` 模块从模块的 docstring 中寻找示例并执行,对比输出是否与 docstring "
"中给出的是否一致。"
#: ../../faq/library.rst:141
msgid ""
"The :mod:`unittest` module is a fancier testing framework modelled on Java "
"and Smalltalk testing frameworks."
msgstr ":mod:`unittest` 模块是一个模仿 Java 和 Smalltalk 测试框架的更棒的测试框架。"
#: ../../faq/library.rst:144
msgid ""
"To make testing easier, you should use good modular design in your program. "
"Your program should have almost all functionality encapsulated in either "
"functions or class methods -- and this sometimes has the surprising and "
"delightful effect of making the program run faster (because local variable "
"accesses are faster than global accesses). Furthermore the program should "
"avoid depending on mutating global variables, since this makes testing much "
"more difficult to do."
msgstr ""
"为了使测试更容易,你应该在程序中使用良好的模块化设计。程序中的绝大多数功能都应该用函数或类方法封装 —— "
"有时这样做会有额外惊喜,程序会运行得更快(因为局部变量比全局变量访问要快)。除此之外,程序应该避免依赖可变的局部变量,这会使得测试困难许多。"
#: ../../faq/library.rst:152
msgid "The \"global main logic\" of your program may be as simple as ::"
msgstr "程序的“全局主逻辑”应该尽量简单:"
#: ../../faq/library.rst:157
msgid "at the bottom of the main module of your program."
msgstr "并放置在程序主模块的最后面。"
#: ../../faq/library.rst:159
msgid ""
"Once your program is organized as a tractable collection of function and "
"class behaviours, you should write test functions that exercise the "
"behaviours. A test suite that automates a sequence of tests can be "
"associated with each module. This sounds like a lot of work, but since "
"Python is so terse and flexible it's surprisingly easy. You can make coding"
" much more pleasant and fun by writing your test functions in parallel with "
"the \"production code\", since this makes it easy to find bugs and even "
"design flaws earlier."
msgstr ""
"一旦你的程序已经组织为一个函数和类行为的有完整集合,你就应该编写测试函数来检测这些行为。 可以将自动执行一系列测试的测试集关联到每个模块。 "
"这听起来似乎需要大量的工作,但是由于 Python 是如此简洁灵活因此它会极其容易。 "
"你可以通过与“生产代码”同步编写测试函数使编程更为愉快和有趣,因为这将更容易并更早发现代码问题甚至设计缺陷。"
#: ../../faq/library.rst:167
msgid ""
"\"Support modules\" that are not intended to be the main module of a program"
" may include a self-test of the module. ::"
msgstr "程序主模块之外的其他“辅助模块”中可以增加自测试的入口。"
#: ../../faq/library.rst:173
msgid ""
"Even programs that interact with complex external interfaces may be tested "
"when the external interfaces are unavailable by using \"fake\" interfaces "
"implemented in Python."
msgstr "通过使用 Python 实现的“假”接口,即使是需要与复杂的外部接口交互的程序也可以在外部接口不可用时进行测试。"
#: ../../faq/library.rst:179
msgid "How do I create documentation from doc strings?"
msgstr "怎样用 docstring 创建文档?"
#: ../../faq/library.rst:181
msgid ""
"The :mod:`pydoc` module can create HTML from the doc strings in your Python "
"source code. An alternative for creating API documentation purely from "
"docstrings is `epydoc <http://epydoc.sourceforge.net/>`_. `Sphinx "
"<http://sphinx-doc.org>`_ can also include docstring content."
msgstr ""
":mod:`pydoc` 模块可以用 Python 源码中的 docstring 创建 HTML 文件。也可以使用 `epydoc "
"<http://epydoc.sourceforge.net/>`_ 来只通过 docstring 创建 API 文档。`Sphinx "
"<http://sphinx-doc.org>`_ 也可以引入 docstring 的内容。"
#: ../../faq/library.rst:188
msgid "How do I get a single keypress at a time?"
msgstr "怎样一次只获取一个按键?"
#: ../../faq/library.rst:190
msgid ""
"For Unix variants there are several solutions. It's straightforward to do "
"this using curses, but curses is a fairly large module to learn."
msgstr "在类 Unix 系统中有多种方案。最直接的方法是使用 curses,但是 curses 模块太大了,难以学习。"
#: ../../faq/library.rst:234
msgid "Threads"
msgstr "线程相关"
#: ../../faq/library.rst:237
msgid "How do I program using threads?"
msgstr "程序中怎样使用线程?"
#: ../../faq/library.rst:239
msgid ""
"Be sure to use the :mod:`threading` module and not the :mod:`_thread` "
"module. The :mod:`threading` module builds convenient abstractions on top of"
" the low-level primitives provided by the :mod:`_thread` module."
msgstr ""
"一定要使用 :mod:`threading` 模块,不要使用 :mod:`_thread` 模块。:mod:`threading` 模块对 "
":mod:`_thread` 模块提供的底层线程原语做了更易用的抽象。"
#: ../../faq/library.rst:245
msgid "None of my threads seem to run: why?"
msgstr "我的线程都没有运行,为什么?"
#: ../../faq/library.rst:247
msgid ""
"As soon as the main thread exits, all threads are killed. Your main thread "
"is running too quickly, giving the threads no time to do any work."
msgstr "一旦主线程退出,所有的子线程都会被杀掉。你的主线程运行得太快了,子线程还没来得及工作。"
#: ../../faq/library.rst:250
msgid ""
"A simple fix is to add a sleep to the end of the program that's long enough "
"for all the threads to finish::"
msgstr "简单的解决方法是在程序中加一个时间足够长的 sleep,让子线程能够完成运行。"
#: ../../faq/library.rst:265
msgid ""
"But now (on many platforms) the threads don't run in parallel, but appear to"
" run sequentially, one at a time! The reason is that the OS thread "
"scheduler doesn't start a new thread until the previous thread is blocked."
msgstr "但目前(在许多平台上)线程不是并行运行的,而是按顺序依次执行!原因是系统线程调度器在前一个线程阻塞之前不会启动新线程。"
#: ../../faq/library.rst:269
msgid "A simple fix is to add a tiny sleep to the start of the run function::"
msgstr "简单的解决方法是在运行函数的开始处加一个时间很短的 sleep。"
#: ../../faq/library.rst:282
msgid ""
"Instead of trying to guess a good delay value for :func:`time.sleep`, it's "
"better to use some kind of semaphore mechanism. One idea is to use the "
":mod:`queue` module to create a queue object, let each thread append a token"
" to the queue when it finishes, and let the main thread read as many tokens "
"from the queue as there are threads."
msgstr ""
"比起用 :func:`time.sleep` 猜一个合适的等待时间,使用信号量机制会更好些。有一个办法是使用 :mod:`queue` 模块创建一个 "
"queue 对象,让每一个线程在运行结束时 append 一个令牌到 queue 对象中,主线程中从 queue "
"对象中读取与线程数量一致的令牌数量即可。"
#: ../../faq/library.rst:290
msgid "How do I parcel out work among a bunch of worker threads?"
msgstr "如何将任务分配给多个工作线程?"
#: ../../faq/library.rst:292
msgid ""
"The easiest way is to use the :mod:`concurrent.futures` module, especially "
"the :mod:`~concurrent.futures.ThreadPoolExecutor` class."
msgstr ""
"最简单的方式是使用 :mod:`concurrent.futures` 模块,特别是其中的 "
":mod:`~concurrent.futures.ThreadPoolExecutor` 类。"
#: ../../faq/library.rst:295
msgid ""
"Or, if you want fine control over the dispatching algorithm, you can write "
"your own logic manually. Use the :mod:`queue` module to create a queue "
"containing a list of jobs. The :class:`~queue.Queue` class maintains a list"
" of objects and has a ``.put(obj)`` method that adds items to the queue and "
"a ``.get()`` method to return them. The class will take care of the locking"
" necessary to ensure that each job is handed out exactly once."
msgstr ""
"或者,如果你想更好地控制分发算法,你也可以自己写逻辑实现。使用 :mod:`queue` "
"模块来创建任务列表队列。:class:`~queue.Queue` 类维护一个了一个存有对象的列表,提供了 ``.put(obj)`` "
"方法添加元素,并且可以用 ``.get()`` 方法获取元素。这个类会使用必要的加锁操作,以此确保每个任务只会执行一次。"
#: ../../faq/library.rst:302
msgid "Here's a trivial example::"
msgstr "这是一个简单的例子:"
#: ../../faq/library.rst:340
msgid "When run, this will produce the following output:"
msgstr "运行时会产生如下输出:"
#: ../../faq/library.rst:358
msgid ""
"Consult the module's documentation for more details; the "
":class:`~queue.Queue` class provides a featureful interface."
msgstr "查看模块的文档以获取更多信息;:class:`~queue.Queue` 类提供了多种接口。"
#: ../../faq/library.rst:363
msgid "What kinds of global value mutation are thread-safe?"
msgstr "怎样修改全局变量是线程安全的?"
#: ../../faq/library.rst:365
msgid ""
"A :term:`global interpreter lock` (GIL) is used internally to ensure that "
"only one thread runs in the Python VM at a time. In general, Python offers "
"to switch among threads only between bytecode instructions; how frequently "
"it switches can be set via :func:`sys.setswitchinterval`. Each bytecode "
"instruction and therefore all the C implementation code reached from each "
"instruction is therefore atomic from the point of view of a Python program."
msgstr ""
"Python VM 内部会使用 :term:`global interpreter lock` (GIL)来确保同一时间只有一个线程运行。通常 "
"Python 只会在字节码指令之间切换线程;切换的频率可以通过设置 :func:`sys.setswitchinterval` 指定。从 Python "
"程序的角度来看,每一条字节码指令以及每一条指令对应的 C 代码实现都是原子的。"
#: ../../faq/library.rst:372
msgid ""
"In theory, this means an exact accounting requires an exact understanding of"
" the PVM bytecode implementation. In practice, it means that operations on "
"shared variables of built-in data types (ints, lists, dicts, etc) that "
"\"look atomic\" really are."
msgstr ""
"理论上说,具体的结果要看具体的 PVM 字节码实现对指令的解释。而实际上,对内建类型(int,list,dict "
"等)的共享变量的“类原子”操作都是原子的。"
#: ../../faq/library.rst:377
msgid ""
"For example, the following operations are all atomic (L, L1, L2 are lists, "
"D, D1, D2 are dicts, x, y are objects, i, j are ints)::"
msgstr "举例来说,下面的操作是原子的(L、L1、L2 是列表,D、D1、D2 是字典,x、y 是对象,i,j 是 int 变量):"
#: ../../faq/library.rst:392
msgid "These aren't::"
msgstr "这些不是原子的:"
#: ../../faq/library.rst:399
msgid ""
"Operations that replace other objects may invoke those other objects' "
":meth:`__del__` method when their reference count reaches zero, and that can"
" affect things. This is especially true for the mass updates to "
"dictionaries and lists. When in doubt, use a mutex!"
msgstr ""
"覆盖其他对象的操作会在其他对象的引用计数变成 0 时触发其 :meth:`__del__` "
"方法,这可能会产生一些影响。对字典和列表进行大量操作时尤其如此。如果有疑问的话,使用互斥锁!"
#: ../../faq/library.rst:406
msgid "Can't we get rid of the Global Interpreter Lock?"
msgstr "不能删除全局解释器锁吗?"
#: ../../faq/library.rst:410
msgid ""
"The :term:`global interpreter lock` (GIL) is often seen as a hindrance to "
"Python's deployment on high-end multiprocessor server machines, because a "
"multi-threaded Python program effectively only uses one CPU, due to the "
"insistence that (almost) all Python code can only run while the GIL is held."
msgstr ""
":term:`global interpreter lock` (GIL)通常被视为 Python 在高端多核服务器上开发时的阻力,因为(几乎)所有 "
"Python 代码只有在获取到 GIL 时才能运行,所以多线程的 Python 程序只能有效地使用一个 CPU。"
#: ../../faq/library.rst:415
msgid ""
"Back in the days of Python 1.5, Greg Stein actually implemented a "
"comprehensive patch set (the \"free threading\" patches) that removed the "
"GIL and replaced it with fine-grained locking. Adam Olsen recently did a "
"similar experiment in his `python-safethread "
"<https://code.google.com/archive/p/python-safethread>`_ project. "
"Unfortunately, both experiments exhibited a sharp drop in single-thread "
"performance (at least 30% slower), due to the amount of fine-grained locking"
" necessary to compensate for the removal of the GIL."
msgstr ""
"在 Python 1.5 时代,Greg Stein 开发了一个完整的补丁包(“free threadings” 补丁),移除了 "
"GIL,并用粒度更合适的锁来代替。Adam Olsen 最近也在他的 `python-safethread "
"<https://code.google.com/archive/p/python-safethread>`_ "
"项目里做了类似的实验。不幸的是,由于为了移除 GIL 而使用了大量细粒度的锁,这两个实验在单线程测试中的性能都有明显的下降(至少慢 30%)。"
#: ../../faq/library.rst:423
msgid ""
"This doesn't mean that you can't make good use of Python on multi-CPU "
"machines! You just have to be creative with dividing the work up between "
"multiple *processes* rather than multiple *threads*. The "
":class:`~concurrent.futures.ProcessPoolExecutor` class in the new "
":mod:`concurrent.futures` module provides an easy way of doing so; the "
":mod:`multiprocessing` module provides a lower-level API in case you want "
"more control over dispatching of tasks."
msgstr ""
"但这并意味着你不能在多核机器上很好地使用 Python!你只需将任务划分为多*进程*,而不是多*线程*。新的 "
":mod:`concurrent.futures` 模块中的 "
":class:`~concurrent.futures.ProcessPoolExecutor` "
"类提供了一个简单的方法;如果你想对任务分发做更多控制,可以使用 :mod:`multiprocessing` 模块提供的底层 API。"
#: ../../faq/library.rst:431
msgid ""
"Judicious use of C extensions will also help; if you use a C extension to "
"perform a time-consuming task, the extension can release the GIL while the "
"thread of execution is in the C code and allow other threads to get some "
"work done. Some standard library modules such as :mod:`zlib` and "
":mod:`hashlib` already do this."
msgstr ""
"恰当地使用 C 拓展也很有用;使用 C 拓展处理耗时较久的任务时,拓展可以在线程执行 C 代码时释放 GIL,让其他线程执行。:mod:`zlib` 和"
" :mod:`hashlib` 等标准库模块已经这样做了。"
#: ../../faq/library.rst:437
msgid ""
"It has been suggested that the GIL should be a per-interpreter-state lock "
"rather than truly global; interpreters then wouldn't be able to share "
"objects. Unfortunately, this isn't likely to happen either. It would be a "
"tremendous amount of work, because many object implementations currently "
"have global state. For example, small integers and short strings are cached;"
" these caches would have to be moved to the interpreter state. Other object"
" types have their own free list; these free lists would have to be moved to "
"the interpreter state. And so on."
msgstr ""
"也有建议说 GIL "
"应该是解释器状态锁,而不是完全的全局锁;解释器不应该共享对象。不幸的是,这也不可能发生。由于目前许多对象的实现都有全局的状态,因此这是一个艰巨的工作。举例来说,小整型数和短字符串会缓存起来,这些缓存将不得不移动到解释器状态中。其他对象类型都有自己的自由变量列表,这些自由变量列表也必须移动到解释器状态中。等等。"
#: ../../faq/library.rst:446
msgid ""
"And I doubt that it can even be done in finite time, because the same "
"problem exists for 3rd party extensions. It is likely that 3rd party "
"extensions are being written at a faster rate than you can convert them to "
"store all their global state in the interpreter state."
msgstr ""
"我甚至怀疑这些工作是否可能在有限的时间内完成,因为同样的问题在第三方拓展中也会存在。第三方拓展编写的速度可比你将它们转换为把全局状态存入解释器状态中的速度快得多。"
#: ../../faq/library.rst:451
msgid ""
"And finally, once you have multiple interpreters not sharing any state, what"
" have you gained over running each interpreter in a separate process?"
msgstr "最后,假设多个解释器不共享任何状态,那么这样做比每个进程一个解释器好在哪里呢?"
#: ../../faq/library.rst:456
msgid "Input and Output"
msgstr "输入输出"
#: ../../faq/library.rst:459
msgid "How do I delete a file? (And other file questions...)"
msgstr "怎样删除文件?(以及其他文件相关的问题……)"
#: ../../faq/library.rst:461
msgid ""
"Use ``os.remove(filename)`` or ``os.unlink(filename)``; for documentation, "
"see the :mod:`os` module. The two functions are identical; "
":func:`~os.unlink` is simply the name of the Unix system call for this "
"function."
msgstr ""
"使用 ``os.remove(filename)`` 或 ``os.unlink(filename)``。查看 :mod:`os` "
"模块以获取更多文档。这两个函数是一样的,:func:`~os.unlink` 是这个函数在 Unix 系统调用中的名字。"
#: ../../faq/library.rst:465
msgid ""
"To remove a directory, use :func:`os.rmdir`; use :func:`os.mkdir` to create "
"one. ``os.makedirs(path)`` will create any intermediate directories in "
"``path`` that don't exist. ``os.removedirs(path)`` will remove intermediate "
"directories as long as they're empty; if you want to delete an entire "
"directory tree and its contents, use :func:`shutil.rmtree`."
msgstr ""
"如果要删除目录,应该使用 :func:`os.rmdir`;使用 :func:`os.mkdir` 创建目录。``os.makedirs(path)``"
" 会创建 ``path`` 中任何不存在的目录。``os.removedirs(path)`` "
"则会删除其中的目录,只要它们都是空的;如果你想删除整个目录以及其中的内容,可以使用 :func:`shutil.rmtree`。"
#: ../../faq/library.rst:471
msgid "To rename a file, use ``os.rename(old_path, new_path)``."
msgstr "重命名文件可以使用 ``os.rename(old_path, new_path)``。"
#: ../../faq/library.rst:473
msgid ""
"To truncate a file, open it using ``f = open(filename, \"rb+\")``, and use "
"``f.truncate(offset)``; offset defaults to the current seek position. "
"There's also ``os.ftruncate(fd, offset)`` for files opened with "
":func:`os.open`, where *fd* is the file descriptor (a small integer)."
msgstr ""
"如果需要截断文件,使用 ``f = open(filename, \"rb+\")`` 打开文件,然后使用 "
"``f.truncate(offset)``;offset 默认是当前的搜索位置。也可以对使用 :func:`os.open` 打开的文件使用 "
"``os.ftruncate(fd, offset)``,其中 *fd* 是文件描述符(一个小的整型数)。"
#: ../../faq/library.rst:478
msgid ""
"The :mod:`shutil` module also contains a number of functions to work on "
"files including :func:`~shutil.copyfile`, :func:`~shutil.copytree`, and "
":func:`~shutil.rmtree`."
msgstr ""
":mod:`shutil` 模块也包含了一些处理文件的函数,包括 "
":func:`~shutil.copyfile`,:func:`~shutil.copytree` 和 :func:`~shutil.rmtree`。"
#: ../../faq/library.rst:484
msgid "How do I copy a file?"
msgstr "怎样复制文件?"
#: ../../faq/library.rst:486
msgid ""
"The :mod:`shutil` module contains a :func:`~shutil.copyfile` function. Note"
" that on MacOS 9 it doesn't copy the resource fork and Finder info."
msgstr ""
":mod:`shutil` 模块有一个 :func:`~shutil.copyfile` 函数。注意在 MacOS 9 中不会复制 resource "
"fork 和 Finder info。"
#: ../../faq/library.rst:491
msgid "How do I read (or write) binary data?"
msgstr "怎样读取(或写入)二进制数据?"
#: ../../faq/library.rst:493
msgid ""
"To read or write complex binary data formats, it's best to use the "
":mod:`struct` module. It allows you to take a string containing binary data"
" (usually numbers) and convert it to Python objects; and vice versa."
msgstr ""
"要读写复杂的二进制数据格式,最好使用 :mod:`struct` 模块。该模块可以读取包含二进制数据(通常是数字)的字符串并转换为 Python "
"对象,反之亦然。"
#: ../../faq/library.rst:497
msgid ""
"For example, the following code reads two 2-byte integers and one 4-byte "
"integer in big-endian format from a file::"
msgstr "举例来说,下面的代码会从文件中以大端序格式读取一个 2 字节的整型和一个 4 字节的整型:"
#: ../../faq/library.rst:506
msgid ""
"The '>' in the format string forces big-endian data; the letter 'h' reads "
"one \"short integer\" (2 bytes), and 'l' reads one \"long integer\" (4 "
"bytes) from the string."
msgstr ""
"格式字符串中的 ‘>’ 强制以大端序读取数据;字母 ‘h’ 从字符串中读取一个“短整型”(2 字节),字母 ‘l’ 读取一个“长整型”(4 字节)。"
#: ../../faq/library.rst:510
msgid ""
"For data that is more regular (e.g. a homogeneous list of ints or floats), "
"you can also use the :mod:`array` module."
msgstr "对于更常规的数据(例如整型或浮点类型的列表),你也可以使用 :mod:`array` 模块。"
#: ../../faq/library.rst:515
msgid ""
"To read and write binary data, it is mandatory to open the file in binary "
"mode (here, passing ``\"rb\"`` to :func:`open`). If you use ``\"r\"`` "
"instead (the default), the file will be open in text mode and ``f.read()`` "
"will return :class:`str` objects rather than :class:`bytes` objects."
msgstr ""
"要读写二进制数据的话,需要强制以二进制模式打开文件(这里为 :func:`open` 函数传入 ``\"rb\"``)。如果(默认)传入 "
"``\"r\"`` 的话,文件会以文本模式打开,``f.read()`` 会返回 :class:`str` 对象,而不是 :class:`bytes` "
"对象。"
#: ../../faq/library.rst:523
msgid "I can't seem to use os.read() on a pipe created with os.popen(); why?"
msgstr "似乎 os.popen() 创建的管道不能使用 os.read(),这是为什么?"
#: ../../faq/library.rst:525
msgid ""
":func:`os.read` is a low-level function which takes a file descriptor, a "
"small integer representing the opened file. :func:`os.popen` creates a "
"high-level file object, the same type returned by the built-in :func:`open` "
"function. Thus, to read *n* bytes from a pipe *p* created with "
":func:`os.popen`, you need to use ``p.read(n)``."
msgstr ""
":func:`os.read` 是一个底层函数,它接收的是文件描述符 —— 用小整型数表示的打开的文件。:func:`os.popen` "
"创建的是一个高级文件对象,和内建的 :func:`open` 方法返回的类型一样。因此,如果要从 :func:`os.popen` 创建的管道 *p* "
"中读取 *n* 个字节的话,你应该使用 ``p.read(n)``。"
#: ../../faq/library.rst:612
msgid "How do I access the serial (RS232) port?"
msgstr "怎样访问(RS232)串口?"
#: ../../faq/library.rst:614
msgid "For Win32, OSX, Linux, BSD, Jython, IronPython:"
msgstr "对于 Win32, OSX, Linux, BSD, Jython, IronPython:"
#: ../../faq/library.rst:616
msgid "https://pypi.org/project/pyserial/"
msgstr "https://pypi.org/project/pyserial/ "
#: ../../faq/library.rst:618
msgid "For Unix, see a Usenet post by Mitch Chapman:"
msgstr "对于 Unix,查看 Mitch Chapman 发布的帖子:"
#: ../../faq/library.rst:620
msgid "https://groups.google.com/groups?selm=34A04430.CF9@ohioee.com"
msgstr "https://groups.google.com/groups?selm=34A04430.CF9@ohioee.com"
#: ../../faq/library.rst:624
msgid "Why doesn't closing sys.stdout (stdin, stderr) really close it?"
msgstr "为什么关闭 sys.stdout(stdin,stderr)并不会真正关掉它?"
#: ../../faq/library.rst:626
msgid ""
"Python :term:`file objects <file object>` are a high-level layer of "
"abstraction on low-level C file descriptors."
msgstr "Python :term:`文件对象 <file object>` 是一个对底层 C 文件描述符的高层抽象。"
#: ../../faq/library.rst:629
msgid ""
"For most file objects you create in Python via the built-in :func:`open` "
"function, ``f.close()`` marks the Python file object as being closed from "
"Python's point of view, and also arranges to close the underlying C file "
"descriptor. This also happens automatically in ``f``'s destructor, when "
"``f`` becomes garbage."
msgstr ""
"对于在 Python 中通过内建的 :func:`open` 函数创建的多数文件对象来说,``f.close()`` 从 Python "
"的角度将其标记为已关闭,并且会关闭底层的 C 文件描述符。在 ``f`` 被垃圾回收的时候,析构函数中也会自动处理。"
#: ../../faq/library.rst:635
msgid ""
"But stdin, stdout and stderr are treated specially by Python, because of the"
" special status also given to them by C. Running ``sys.stdout.close()`` "
"marks the Python-level file object as being closed, but does *not* close the"
" associated C file descriptor."
msgstr ""
"但由于 stdin,stdout 和 stderr 在 C 中的特殊地位,在 Python 中也会对它们做特殊处理。运行 "
"``sys.stdout.close()`` 会将 Python 的文件对象标记为已关闭,但是*不会*关闭与之关联的文件描述符。"
#: ../../faq/library.rst:640
msgid ""
"To close the underlying C file descriptor for one of these three, you should"
" first be sure that's what you really want to do (e.g., you may confuse "
"extension modules trying to do I/O). If it is, use :func:`os.close`::"
msgstr ""
"要关闭这三者的 C 文件描述符的话,首先你应该确认确实需要关闭它(比如,这可能会影响到处理 I/O 的拓展)。如果确实需要这么做的话,使用 "
":func:`os.close`:"
#: ../../faq/library.rst:648
msgid "Or you can use the numeric constants 0, 1 and 2, respectively."
msgstr "或者也可以使用常量 0,1,2 代替。"
#: ../../faq/library.rst:652
msgid "Network/Internet Programming"
msgstr "网络 / Internet 编程"
#: ../../faq/library.rst:655
msgid "What WWW tools are there for Python?"
msgstr "Python 中的 WWW 工具是什么?"
#: ../../faq/library.rst:657
msgid ""
"See the chapters titled :ref:`internet` and :ref:`netdata` in the Library "
"Reference Manual. Python has many modules that will help you build server-"
"side and client-side web systems."
msgstr ""
"参阅代码库参考手册中 :ref:`internet` 和 :ref:`netdata` 这两章的内容。Python 有大量模块来帮助你构建服务端和客户端"
" web 系统。"
#: ../../faq/library.rst:663
msgid ""
"A summary of available frameworks is maintained by Paul Boddie at "
"https://wiki.python.org/moin/WebProgramming\\ ."
msgstr ""
"Paul Boddie 维护了一份可用框架的概览,见 https://wiki.python.org/moin/WebProgramming 。"
#: ../../faq/library.rst:666
msgid ""
"Cameron Laird maintains a useful set of pages about Python web technologies "
"at http://phaseit.net/claird/comp.lang.python/web_python."
msgstr ""
"Cameron Laird 维护了一份关于 Python web 技术的实用网页的集合,见 "
"http://phaseit.net/claird/comp.lang.python/web_python 。"
#: ../../faq/library.rst:671
msgid "How can I mimic CGI form submission (METHOD=POST)?"
msgstr "怎样模拟发送 CGI 表单(METHOD=POST)?"
#: ../../faq/library.rst:673
msgid ""
"I would like to retrieve web pages that are the result of POSTing a form. Is"
" there existing code that would let me do this easily?"
msgstr "我需要通过 POST 表单获取网页,有什么代码能简单做到吗?"
#: ../../faq/library.rst:676
msgid "Yes. Here's a simple example that uses :mod:`urllib.request`::"
msgstr "是的。 这里是一个使用 :mod:`urllib.request` 的简单例子::"
#: ../../faq/library.rst:691
msgid ""
"Note that in general for percent-encoded POST operations, query strings must"
" be quoted using :func:`urllib.parse.urlencode`. For example, to send "
"``name=Guy Steele, Jr.``::"
msgstr ""
"注意,通常在百分号编码的 POST 操作中,查询字符串必须使用 :func:`urllib.parse.urlencode` "
"处理一下。举个例子,如果要发送 ``name=Guy Steele, Jr.`` 的话:"
#: ../../faq/library.rst:699
msgid ":ref:`urllib-howto` for extensive examples."
msgstr "查看 :ref:`urllib-howto` 获取更多示例。"
#: ../../faq/library.rst:703
msgid "What module should I use to help with generating HTML?"
msgstr "生成 HTML 需要使用什么模块?"
#: ../../faq/library.rst:707
msgid ""
"You can find a collection of useful links on the `Web Programming wiki page "
"<https://wiki.python.org/moin/WebProgramming>`_."
msgstr ""
"你可以在 `Web 编程 wiki 页面 <https://wiki.python.org/moin/WebProgramming>`_ "
"找到许多有用的链接。"
#: ../../faq/library.rst:712
msgid "How do I send mail from a Python script?"
msgstr "怎样使用 Python 脚本发送邮件?"
#: ../../faq/library.rst:714
msgid "Use the standard library module :mod:`smtplib`."
msgstr "使用 :mod:`smtplib` 标准库模块。"
#: ../../faq/library.rst:716
msgid ""
"Here's a very simple interactive mail sender that uses it. This method will"
" work on any host that supports an SMTP listener. ::"
msgstr "下面是一个很简单的交互式发送邮件的代码。这个方法适用于任何支持 SMTP 协议的主机。"
#: ../../faq/library.rst:736
msgid ""
"A Unix-only alternative uses sendmail. The location of the sendmail program"
" varies between systems; sometimes it is ``/usr/lib/sendmail``, sometimes "
"``/usr/sbin/sendmail``. The sendmail manual page will help you out. Here's"
" some sample code::"
msgstr ""
"在 Unix 系统中还可以使用 sendmail。sendmail 程序的位置在不同系统中不一样,有时是在 "
"``/usr/lib/sendmail``,有时是在 ``/usr/sbin/sendmail``。sendmail "
"手册页面会对你有所帮助。以下是示例代码:"
#: ../../faq/library.rst:756
msgid "How do I avoid blocking in the connect() method of a socket?"
msgstr "socket 的 connect() 方法怎样避免阻塞?"
#: ../../faq/library.rst:758
msgid ""
"The :mod:`select` module is commonly used to help with asynchronous I/O on "
"sockets."
msgstr "通常会用 :mod:`select` 模块处理 socket 异步 I/O。"
#: ../../faq/library.rst:761
msgid ""
"To prevent the TCP connect from blocking, you can set the socket to non-"
"blocking mode. Then when you do the :meth:`socket.connect`, you will either"
" connect immediately (unlikely) or get an exception that contains the error "
"number as ``.errno``. ``errno.EINPROGRESS`` indicates that the connection is"
" in progress, but hasn't finished yet. Different OSes will return different"
" values, so you're going to have to check what's returned on your system."
msgstr ""
"要防止 TCP 连接发生阻塞,你可以将 socket 设为非阻塞模式。 这样当你执行 :meth:`socket.connect` "
"时,你将或是立即完成连接(不大可能)或是收到一个包含 ``.errno`` 错误码的异常。 ``errno.EINPROGRESS`` "
"表示连接正在进行但还没有完成。 不同的操作系统将返回不同的值,因此你需要确认你的系统会返回什么值。"
#: ../../faq/library.rst:768
msgid ""
"You can use the :meth:`socket.connect_ex` method to avoid creating an "
"exception. It will just return the errno value. To poll, you can call "
":meth:`socket.connect_ex` again later -- ``0`` or ``errno.EISCONN`` indicate"
" that you're connected -- or you can pass this socket to "
":meth:`select.select` to check if it's writable."
msgstr ""
"你可以使用 :meth:`socket.connect_ex` 方法来避免生成异常。 它将只返回 errno 值。 要进行轮询,你可以稍后再次调用 "
":meth:`socket.connect_ex` -- ``0`` 或 ``errno.EISCONN`` 表示连接已完成 -- 或者你也可以将此 "
"socket 传给 :meth:`select.select` 来检查它是否可写。"
#: ../../faq/library.rst:774
msgid ""
"The :mod:`asyncio` module provides a general purpose single-threaded and "
"concurrent asynchronous library, which can be used for writing non-blocking "
"network code. The third-party `Twisted <https://twistedmatrix.com/trac/>`_ "
"library is a popular and feature-rich alternative."
msgstr ""
":mod:`asyncio` 模块提供了通用的单线程并发异步库,它可被用来编写非阻塞的网络代码。 第三方的 `Twisted "
"<https://twistedmatrix.com/trac/>`_ 库是一个热门且功能丰富的替代选择。"
#: ../../faq/library.rst:782
msgid "Databases"
msgstr "数据库"
#: ../../faq/library.rst:785
msgid "Are there any interfaces to database packages in Python?"
msgstr "Python 中有数据库包的接口吗?"
#: ../../faq/library.rst:787
msgid "Yes."
msgstr "当然。"
#: ../../faq/library.rst:789
msgid ""
"Interfaces to disk-based hashes such as :mod:`DBM <dbm.ndbm>` and :mod:`GDBM"
" <dbm.gnu>` are also included with standard Python. There is also the "
":mod:`sqlite3` module, which provides a lightweight disk-based relational "
"database."
msgstr ""
"标准 Python 还包含了基于磁盘的哈希接口例如 :mod:`DBM <dbm.ndbm>` 和 :mod:`GDBM <dbm.gnu>` "
"。除此之外还有 :mod:`sqlite3` 模块,该模块提供了一个轻量级的基于磁盘的关系型数据库。"
#: ../../faq/library.rst:794
msgid ""
"Support for most relational databases is available. See the "
"`DatabaseProgramming wiki page "
"<https://wiki.python.org/moin/DatabaseProgramming>`_ for details."
msgstr ""
"大多数关系型数据库都已经支持。查看 `数据库编程 wiki 页面 "
"<https://wiki.python.org/moin/DatabaseProgramming>`_ 获取更多信息。"
#: ../../faq/library.rst:800
msgid "How do you implement persistent objects in Python?"
msgstr "在 Python 中如何实现持久化对象?"
#: ../../faq/library.rst:802
msgid ""
"The :mod:`pickle` library module solves this in a very general way (though "
"you still can't store things like open files, sockets or windows), and the "
":mod:`shelve` library module uses pickle and (g)dbm to create persistent "
"mappings containing arbitrary Python objects."
msgstr ""
":mod:`pickle` 库模块以一种非常通用的方式解决了这个问题(虽然你依然不能用它保存打开的文件、套接字或窗口之类的东西),此外 "
":mod:`shelve` 库模块可使用 pickle 和 (g)dbm 来创建包含任意 Python 对象的持久化映射。"
#: ../../faq/library.rst:809
msgid "Mathematics and Numerics"
msgstr "数学和数字"
#: ../../faq/library.rst:812
msgid "How do I generate random numbers in Python?"
msgstr "Python 中怎样生成随机数?"
#: ../../faq/library.rst:814
msgid ""
"The standard module :mod:`random` implements a random number generator. "
"Usage is simple::"
msgstr ":mod:`random` 标准库模块实现了随机数生成器,使用起来非常简单:"
#: ../../faq/library.rst:820
msgid "This returns a random floating point number in the range [0, 1)."
msgstr "这个函数会返回 [0, 1) 之间的随机浮点数。"
#: ../../faq/library.rst:822
msgid ""
"There are also many other specialized generators in this module, such as:"
msgstr "该模块中还有许多其他的专门的生成器,例如:"
#: ../../faq/library.rst:824
msgid "``randrange(a, b)`` chooses an integer in the range [a, b)."
msgstr "``randrange(a, b)`` 返回 [a, b) 区间内的一个整型数。"
#: ../../faq/library.rst:825
msgid "``uniform(a, b)`` chooses a floating point number in the range [a, b)."
msgstr "``uniform(a, b)`` 返回 [a, b) 区间之间的浮点数。"
#: ../../faq/library.rst:826
msgid ""
"``normalvariate(mean, sdev)`` samples the normal (Gaussian) distribution."
msgstr "``normalvariate(mean, sdev)`` 使用正态(高斯)分布采样。"
#: ../../faq/library.rst:828
msgid "Some higher-level functions operate on sequences directly, such as:"
msgstr "还有一些高级函数直接对序列进行操作,例如:"
#: ../../faq/library.rst:830
msgid "``choice(S)`` chooses a random element from a given sequence."
msgstr "``choice(S)`` 从给定的序列中随机选择一个元素。"
#: ../../faq/library.rst:831
msgid "``shuffle(L)`` shuffles a list in-place, i.e. permutes it randomly."
msgstr "``shuffle(L)`` 会对列表执行原地重排,即将其随机地打乱。"
#: ../../faq/library.rst:833
msgid ""
"There's also a ``Random`` class you can instantiate to create independent "
"multiple random number generators."
msgstr "还有 ``Random`` 类,你可以将其实例化,用来创建多个独立的随机数生成器。"