-
-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathprogramming.po
2283 lines (1912 loc) · 148 KB
/
programming.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
# SOME DESCRIPTIVE TITLE.
# Copyright (C) 1990-2021, Python Software Foundation
# This file is distributed under the same license as the Python package.
#
# Translators:
# tomo, 2017
# 秘湯 <[email protected]>, 2015
msgid ""
msgstr ""
"Project-Id-Version: Python 2.7\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-01-01 01:01+0900\n"
"PO-Revision-Date: 2019-09-01 05:22+0000\n"
"Last-Translator: tomo\n"
"Language-Team: Japanese (http://www.transifex.com/python-doc/python-27/language/ja/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: ja\n"
"Plural-Forms: nplurals=1; plural=0;\n"
#: ../../faq/programming.rst:5
msgid "Programming FAQ"
msgstr "プログラミング FAQ"
#: ../../faq/programming.rst:8
msgid "Contents"
msgstr "内容"
#: ../../faq/programming.rst:12
msgid "General Questions"
msgstr "一般的な質問"
#: ../../faq/programming.rst:15
msgid ""
"Is there a source code level debugger with breakpoints, single-stepping, "
"etc.?"
msgstr "ブレークポイントやシングルステップ実行などを備えたソースコードレベルデバッガはありますか?"
#: ../../faq/programming.rst:17 ../../faq/programming.rst:60
msgid "Yes."
msgstr "はい。"
#: ../../faq/programming.rst:19
msgid ""
"The pdb module is a simple but adequate console-mode debugger for Python. It"
" is part of the standard Python library, and is :mod:`documented in the "
"Library Reference Manual <pdb>`. You can also write your own debugger by "
"using the code for pdb as an example."
msgstr "pdb モジュールは簡素にして十分な Python のコンソールモードデバッガです。これは Python の標準ライブラリに含まれているもので、 :mod:`ライブラリリファレンスマニュアルにドキュメントがあります <pdb>` 。 pdb のコードを手本にして自分用のデバッガを書くこともできます。"
#: ../../faq/programming.rst:24
msgid ""
"The IDLE interactive development environment, which is part of the standard "
"Python distribution (normally available as Tools/scripts/idle), includes a "
"graphical debugger."
msgstr "Python に同梱されている統合開発環境の IDLE は通常の Python の配布形態の一部 (普通は Tools/scripts/idle から利用可能) であり、グラフィカルなデバッガを含んでいます。"
#: ../../faq/programming.rst:28
msgid ""
"PythonWin is a Python IDE that includes a GUI debugger based on pdb. The "
"Pythonwin debugger colors breakpoints and has quite a few cool features such"
" as debugging non-Pythonwin programs. Pythonwin is available as part of the"
" `Python for Windows Extensions "
"<https://sourceforge.net/projects/pywin32/>`__ project and as a part of the "
"ActivePython distribution (see https://www.activestate.com/activepython\\ )."
msgstr "PythonWin は、pdb をベースとした GUI デバッガを含む Python IDE です。Pythonwin デバッガは、ブレークポイントの色付けや非 Pythonwin プログラムのデバッグなどのたくさんの素敵な機能を持っています。Pythonwin は `Python for Windows Extensions <https://sourceforge.net/projects/pywin32/>`__ プロジェクトの一部、あるいは ActivePython ディストリビューション (https://www.activestate.com/activepython を参照) の一部として利用可能です。"
#: ../../faq/programming.rst:35
msgid ""
"`Boa Constructor <http://boa-constructor.sourceforge.net/>`_ is an IDE and "
"GUI builder that uses wxWidgets. It offers visual frame creation and "
"manipulation, an object inspector, many views on the source like object "
"browsers, inheritance hierarchies, doc string generated html documentation, "
"an advanced debugger, integrated help, and Zope support."
msgstr "`Boa Constructor <http://boa-constructor.sourceforge.net/>`_ は、wxWidgets を使った IDE と GUI ビルダーです。これは視覚フレームの作成と操作、オブジェクト検査、オブジェクトブラウザのような多くのビュー、継承構造、doc string から生成される html ドキュメント、高度なデバッガ、総合ヘルプ、Zope のサポートを提供します。"
#: ../../faq/programming.rst:41
msgid ""
"`Eric <http://eric-ide.python-projects.org/>`_ is an IDE built on PyQt and "
"the Scintilla editing component."
msgstr "`Eric <http://eric-ide.python-projects.org/>`_ は PyQt や Scintilla editing component をもとにした IDE です。"
#: ../../faq/programming.rst:44
msgid ""
"Pydb is a version of the standard Python debugger pdb, modified for use with"
" DDD (Data Display Debugger), a popular graphical debugger front end. Pydb "
"can be found at http://bashdb.sourceforge.net/pydb/ and DDD can be found at "
"https://www.gnu.org/software/ddd."
msgstr "Pydb は標準のデバッガである pdb を人気のグラフィカルデバッガフロントエンドである DDD (Data Display Debugger) とともに使うために改変したものです。Pydb は http://bashdb.sourceforge.net/pydb/ に、 DDD は https://www.gnu.org/software/ddd にあります。 "
#: ../../faq/programming.rst:49
msgid ""
"There are a number of commercial Python IDEs that include graphical "
"debuggers. They include:"
msgstr "商業のグラフィカルデバッガ付き Python IDE もあります。例えば:"
#: ../../faq/programming.rst:52
msgid "Wing IDE (https://wingware.com/)"
msgstr "Wing IDE (https://wingware.com/)"
#: ../../faq/programming.rst:53
msgid "Komodo IDE (https://komodoide.com/)"
msgstr "Komodo IDE (https://komodoide.com/)"
#: ../../faq/programming.rst:54
msgid "PyCharm (https://www.jetbrains.com/pycharm/)"
msgstr "PyCharm (https://www.jetbrains.com/pycharm/)"
#: ../../faq/programming.rst:58
msgid "Is there a tool to help find bugs or perform static analysis?"
msgstr "バグの発見や静的分析に役立つツールはありますか?"
#: ../../faq/programming.rst:62
msgid ""
"PyChecker is a static analysis tool that finds bugs in Python source code "
"and warns about code complexity and style. You can get PyChecker from "
"http://pychecker.sourceforge.net/."
msgstr "PyChecker は Python ソースコードのバグを発見しコードの複雑さとスタイルについて警告する静的解析ツールです。PyChecker は http://pychecker.sourceforge.net/ から手に入ります。"
#: ../../faq/programming.rst:66
msgid ""
"`Pylint <https://www.pylint.org/>`_ is another tool that checks if a module "
"satisfies a coding standard, and also makes it possible to write plug-ins to"
" add a custom feature. In addition to the bug checking that PyChecker "
"performs, Pylint offers some additional features such as checking line "
"length, whether variable names are well-formed according to your coding "
"standard, whether declared interfaces are fully implemented, and more. "
"https://docs.pylint.org/ provides a full list of Pylint's features."
msgstr "`Pylint <https://www.pylint.org/>`_ も、モジュールがコーディング標準を満たすかを調べ、プラグインを書いてカスタム機能を加えられるようにするツールです。PyChecker が行うバグチェックに加え、 Pylint は行の長さ、変数名が一貫しているか、宣言されたインタフェースが完全に実装されているか、などを確かめる追加の機能を提供します。 https://docs.pylint.org/ で Pylint の機能の一覧を見られます。"
#: ../../faq/programming.rst:76
msgid "How can I create a stand-alone binary from a Python script?"
msgstr "どうしたら Python スクリプトからスタンドアロンバイナリを作れますか?"
#: ../../faq/programming.rst:78
msgid ""
"You don't need the ability to compile Python to C code if all you want is a "
"stand-alone program that users can download and run without having to "
"install the Python distribution first. There are a number of tools that "
"determine the set of modules required by a program and bind these modules "
"together with a Python binary to produce a single executable."
msgstr "ユーザがダウンロードや起動のために Python ディストリビューションをインストールしなくてもよいスタンドアロンプログラムのためだけなら、Python を C コードにコンパイルできる必要はありません。プログラムに対して必要なモジュールを選び、そのモジュールを Python バイナリに束縛して一つの実行可能ファイルにまとめる多くのツールがあります。"
#: ../../faq/programming.rst:84
msgid ""
"One is to use the freeze tool, which is included in the Python source tree "
"as ``Tools/freeze``. It converts Python byte code to C arrays; a C compiler "
"you can embed all your modules into a new program, which is then linked with"
" the standard Python modules."
msgstr "一つは freeze ツールで、Python ソースツリーに ``Tools/freeze`` として含まれています。これは Python バイトコードを C 配列に変換します。すべてのモジュールを標準 Python モジュールにリンクされる新しいプログラムに埋め込む C コンパイラです。"
#: ../../faq/programming.rst:89
msgid ""
"It works by scanning your source recursively for import statements (in both "
"forms) and looking for the modules in the standard Python path as well as in"
" the source directory (for built-in modules). It then turns the bytecode "
"for modules written in Python into C code (array initializers that can be "
"turned into code objects using the marshal module) and creates a custom-made"
" config file that only contains those built-in modules which are actually "
"used in the program. It then compiles the generated C code and links it "
"with the rest of the Python interpreter to form a self-contained binary "
"which acts exactly like your script."
msgstr "これはあなたのソースの (両方の形式の) import 文を再帰的にスキャンして、import されたモジュールを標準の Python パスと (組み込みモジュールのある) ソースディレクトリから探します。そして Python で書かれたモジュールのバイトコードを C コード (marshal モジュールでコードオブジェクトに変換できる配列) に変換し、実際にそのプログラム内で使われている組み込みモジュールだけが含まれたカスタムメイドの設定ファイルを作成します。そして生成された C コードをコンパイルして Python インタプリタの残りとリンクし、元のスクリプトと全く同じように動作する自己充足的なバイナリを形成します。"
#: ../../faq/programming.rst:98
msgid ""
"Obviously, freeze requires a C compiler. There are several other utilities "
"which don't. One is Thomas Heller's py2exe (Windows only) at"
msgstr "もちろん、凍結には C コンパイラが必要です。C コンパイラを必要としない選択肢もあります。その一つは、Thomas Heller の py2exe (Windows 専用) です"
#: ../../faq/programming.rst:101
msgid "http://www.py2exe.org/"
msgstr "http://www.py2exe.org/"
#: ../../faq/programming.rst:103
msgid ""
"Another tool is Anthony Tuininga's `cx_Freeze <http://cx-"
"freeze.sourceforge.net/>`_."
msgstr "他には Anthony Tuininga の `cx_Freeze <http://cx-freeze.sourceforge.net/>`_ があります。"
#: ../../faq/programming.rst:107
msgid "Are there coding standards or a style guide for Python programs?"
msgstr "Python プログラムのためのコーディングスタンダードやスタイルガイドはありますか?"
#: ../../faq/programming.rst:109
msgid ""
"Yes. The coding style required for standard library modules is documented "
"as :pep:`8`."
msgstr "はい。標準ライブラリモジュールに求められるコーディングスタイルは :pep:`8` として文書化されています。"
#: ../../faq/programming.rst:114
msgid "My program is too slow. How do I speed it up?"
msgstr "プログラムが遅すぎます。どうしたら速くなりますか?"
#: ../../faq/programming.rst:116
msgid ""
"That's a tough one, in general. There are many tricks to speed up Python "
"code; consider rewriting parts in C as a last resort."
msgstr "一般に、それは難しい質問です。Python コードを速くするためには、いろいろな手法があります。最終手段として一部を C で書き直す事も考えてください。"
#: ../../faq/programming.rst:119
msgid ""
"In some cases it's possible to automatically translate Python to C or x86 "
"assembly language, meaning that you don't have to modify your code to gain "
"increased speed."
msgstr "Python を自動的に C や x86 アセンブリ言語に変換できる場合もあります。この場合、速度を上げるためにコードを変更する必要はありません。"
#: ../../faq/programming.rst:125
msgid ""
"`Pyrex <http://www.cosc.canterbury.ac.nz/~greg/python/Pyrex/>`_ can compile "
"a slightly modified version of Python code into a C extension, and can be "
"used on many different platforms."
msgstr "`Pyrex <http://www.cosc.canterbury.ac.nz/~greg/python/Pyrex/>`_ はPython コードの少し変化した版を C 拡張にコンパイルでき、多様なプラットフォームで使えます。(訳注: Pyrex は `Cython <https://pypi.python.org/pypi/Cython/>`_ に取って代わられています。)"
#: ../../faq/programming.rst:129
msgid ""
"`Psyco <http://psyco.sourceforge.net>`_ is a just-in-time compiler that "
"translates Python code into x86 assembly language. If you can use it, Psyco"
" can provide dramatic speedups for critical functions."
msgstr "`Psyco <http://psyco.sourceforge.net>`_ は Python コードを x86 アセンブリ言語に変換する実行時コンパイラです。これを使うことが出来れば、重要な関数を劇的にスピードアップできます。"
#: ../../faq/programming.rst:133
msgid ""
"The rest of this answer will discuss various tricks for squeezing a bit more"
" speed out of Python code. *Never* apply any optimization tricks unless you"
" know you need them, after profiling has indicated that a particular "
"function is the heavily executed hot spot in the code. Optimizations almost"
" always make the code less clear, and you shouldn't pay the costs of reduced"
" clarity (increased development time, greater likelihood of bugs) unless the"
" resulting performance benefit is worth it."
msgstr "あとは、Python コードからもう少し速度を搾り出すための様々な手法について議論することになります。コード中の特定の関数が処理が集中するホットスポットで、最適化が必要であると認められない限り、\\ *決して* いかなる最適化の手法も使わないでください。最適化はたいていコードを分かりづらくするので、分かりづらさのコスト (開発時間の延長とバグの可能性の増大) がそれに見合ったパフォーマンスの向上につながらないのであれば元が取れません。"
#: ../../faq/programming.rst:141
msgid ""
"There is a page on the wiki devoted to `performance tips "
"<https://wiki.python.org/moin/PythonSpeed/PerformanceTips>`_."
msgstr "`performance tips <http://wiki.python.org/moin/PythonSpeed/PerformanceTips>`_ に関するページが wiki にあります。"
#: ../../faq/programming.rst:144
msgid ""
"Guido van Rossum has written up an anecdote related to optimization at "
"https://www.python.org/doc/essays/list2str."
msgstr "Guido van Rossum は https://www.python.org/doc/essays/list2str で最適化に関する逸話を詳述しています。"
#: ../../faq/programming.rst:147
msgid ""
"One thing to notice is that function and (especially) method calls are "
"rather expensive; if you have designed a purely OO interface with lots of "
"tiny functions that don't do much more than get or set an instance variable "
"or call another method, you might consider using a more direct way such as "
"directly accessing instance variables. Also see the standard module "
":mod:`profile` which makes it possible to find out where your program is "
"spending most of its time (if you have some patience -- the profiling itself"
" can slow your program down by an order of magnitude)."
msgstr "なお、関数や(特に)メソッドの呼び出しはかなり高価です。インスタンス変数を get や set したり他のメソッドを呼び出す程度の小さな関数がたくさんある純粋 OO インタフェースをデザインしているなら、インスタンス変数に直接アクセスするようなもっと直接的な方法も考えてみてください。また、どのプログラムが実行時間の大部分を占めているかを見つける標準モジュール :mod:`profile` も参照してください (ちょっと忍耐できればの話ですが - プロファイリングはそれ自体がプログラムを一桁ほど遅くしてしまいます)。"
#: ../../faq/programming.rst:156
msgid ""
"Remember that many standard optimization heuristics you may know from other "
"programming experience may well apply to Python. For example it may be "
"faster to send output to output devices using larger writes rather than "
"smaller ones in order to reduce the overhead of kernel system calls. Thus "
"CGI scripts that write all output in \"one shot\" may be faster than those "
"that write lots of small pieces of output."
msgstr "もちろん、他のプログラミングの経験から得られた多くの標準的な最適化の発見的手法は Python にもよく当てはまることが多いです。たとえば、出力装置に出力を送るときに、一度に少なく書くよりもむしろ多く書いたほうが、カーネルのシステムコールのオーバーヘッドを減らすことができて、速くなるでしょう。したがって、CGI スクリプトは \"一発\" ですべて書き出すもののほうが小さなたくさんの出力に分けて書き出すものよりも速くなるでしょう。"
#: ../../faq/programming.rst:163
msgid ""
"Also, be sure to use Python's core features where appropriate. For example,"
" slicing allows programs to chop up lists and other sequence objects in a "
"single tick of the interpreter's mainloop using highly optimized C "
"implementations. Thus to get the same effect as::"
msgstr "また、必ず Python のコアな機能を適切に使ってください。例えば、スライシングなら、リストや他のシーケンスオブジェクトを、高度に最適化された C 実装で、インタプリタのメインループの一刻みで細切れにできます。こうして効果を得ることができる例は::"
#: ../../faq/programming.rst:172
msgid "it is much shorter and far faster to use ::"
msgstr "こう使えばずっと短く、ずっと速くできます::"
#: ../../faq/programming.rst:176
msgid ""
"Note that the functionally-oriented built-in functions such as :func:`map`, "
":func:`zip`, and friends can be a convenient accelerator for loops that "
"perform a single task. For example to pair the elements of two lists "
"together::"
msgstr "関数指向組み込み関数 :func:`map` や :func:`zip` なども一つのタスクを実行するためのループを加速するのに便利であることに注意してください。例えば、二つのリストの要素を組み合わせるためには::"
#: ../../faq/programming.rst:184
msgid "or to compute a number of sines::"
msgstr "また、正弦を一度に計算するには::"
#: ../../faq/programming.rst:189
msgid "The operation completes very quickly in such cases."
msgstr "このような場合には素早く演算が完了します。"
#: ../../faq/programming.rst:191
msgid ""
"Other examples include the ``join()`` and ``split()`` :ref:`methods of "
"string objects <string-methods>`. For example if s1..s7 are large (10K+) "
"strings then ``\"\".join([s1,s2,s3,s4,s5,s6,s7])`` may be far faster than "
"the more obvious ``s1+s2+s3+s4+s5+s6+s7``, since the \"summation\" will "
"compute many subexpressions, whereas ``join()`` does all the copying in one "
"pass. For manipulating strings, use the ``replace()`` and the ``format()`` "
":ref:`methods on string objects <string-methods>`. Use regular expressions "
"only when you're not dealing with constant string patterns. You may still "
"use :ref:`the old % operations <string-formatting>` ``string % tuple`` and "
"``string % dictionary``."
msgstr "その他の例には、 :ref:`文字列オブジェクトのメソッド <string-methods>` ``join()`` 、 ``split()`` などが挙げられます。例えば s1..s7 が大きな (10K+) 文字列の時、 ``\"\".join([s1,s2,s3,s4,s5,s6,s7])`` は単純に ``s1+s2+s3+s4+s5+s6+s7`` とするよりもはるかに速くなるでしょう。なぜなら、 ``join()`` はすべてのコピーを一括して行うのに対し、「足し算」が多くの副演算を行うからです。文字列を扱うには、 :ref:`文字列オブジェクトのメソッド <string-methods>` ``replace()`` 、 ``format()`` を使ってください。正規表現を使うのは、決まった文字列のパターンを使わない時だけにしてください。 :ref:`旧式の % 演算 <string-formatting>` ``string % tuple`` と ``string % dictionary`` も使えます。"
#: ../../faq/programming.rst:202
msgid ""
"Be sure to use the :meth:`list.sort` built-in method to do sorting, and see "
"the `sorting mini-HOWTO <https://wiki.python.org/moin/HowTo/Sorting>`_ for "
"examples of moderately advanced usage. :meth:`list.sort` beats other "
"techniques for sorting in all but the most extreme circumstances."
msgstr "ソートには必ずビルトインオブジェクトの :meth:`list.sort` を使ってください。また、 `sorting mini-HOWTO <https://wiki.python.org/moin/HowTo/Sorting>`_ の少し高度な使い方の例を参照してください。 :meth:`list.sort` は、よほど極端な状況でない限り、他のソートの技術に勝ります。"
#: ../../faq/programming.rst:207
msgid ""
"Another common trick is to \"push loops into functions or methods.\" For "
"example suppose you have a program that runs slowly and you use the profiler"
" to determine that a Python function ``ff()`` is being called lots of times."
" If you notice that ``ff()``::"
msgstr "「ループを関数やメソッドの中に入れ込む」というのも一般的な手法です。例えば、遅いプログラムがあって、Python の ``ff()`` 関数が何度も呼ばれていることがプロファイラで分かったとします。この ``ff()`` ::"
#: ../../faq/programming.rst:216
msgid "tends to be called in loops like::"
msgstr "がこのようなループで呼ばれる傾向がある気付いたとして::"
#: ../../faq/programming.rst:220
msgid "or::"
msgstr "もしくは::"
#: ../../faq/programming.rst:226
msgid ""
"then you can often eliminate function call overhead by rewriting ``ff()`` "
"to::"
msgstr "``ff()`` を書き換えて::"
#: ../../faq/programming.rst:235
msgid "and rewrite the two examples to ``list = ffseq(oldlist)`` and to::"
msgstr "また、上の二つの例を、 ``list = ffseq(oldlist)`` と::"
#: ../../faq/programming.rst:240
msgid ""
"Single calls to ``ff(x)`` translate to ``ffseq([x])[0]`` with little "
"penalty. Of course this technique is not always appropriate and there are "
"other variants which you can figure out."
msgstr "のように書き換えることによって、関数を呼ぶためのオーバーヘッドを省けることが多いです。``ff(x)`` を一回だけ呼ぶ場合、 ``ffseq([x])[0]`` に直してしまうとちょっと不利になります。 もちろん、このテクニックがいつでも適切であるわけではありませんし、解決のための他の方法もあります。"
#: ../../faq/programming.rst:244
msgid ""
"You can gain some performance by explicitly storing the results of a "
"function or method lookup into a local variable. A loop like::"
msgstr "関数やメソッドの探索の結果をローカル変数に明示的に保存すると少しパフォーマンスが良くなります。次のようなループ::"
#: ../../faq/programming.rst:250
msgid ""
"resolves ``dict.get`` every iteration. If the method isn't going to change,"
" a slightly faster implementation is::"
msgstr "は、繰り返しのたびに ``dict.get`` を求めています。 このメソッドが変わることがないのなら、少し速い実装は::"
#: ../../faq/programming.rst:257
msgid ""
"Default arguments can be used to determine values once, at compile time "
"instead of at run time. This can only be done for functions or objects "
"which will not be changed during program execution, such as replacing ::"
msgstr "デフォルト引数は、実行時でなく、コンパイル時に値を一回で決めてしまうのに使えます。これは、プログラムの実行中に変化しない関数やオブジェクト、例えば::"
#: ../../faq/programming.rst:264
msgid "with ::"
msgstr "を、次のように置き換えるときにのみ行えます::"
#: ../../faq/programming.rst:269
msgid ""
"Because this trick uses default arguments for terms which should not be "
"changed, it should only be used when you are not concerned with presenting a"
" possibly confusing API to your users."
msgstr "この手法はデフォルト引数が変えられないことを前提に使うので、ユーザーが API で混乱するおそれがないときのみ使えます。"
#: ../../faq/programming.rst:275
msgid "Core Language"
msgstr "コア言語"
#: ../../faq/programming.rst:278
msgid "Why am I getting an UnboundLocalError when the variable has a value?"
msgstr "なぜ変数に値があるのに UnboundLocalError が出るのですか?"
#: ../../faq/programming.rst:280
msgid ""
"It can be a surprise to get the UnboundLocalError in previously working code"
" when it is modified by adding an assignment statement somewhere in the body"
" of a function."
msgstr "もともと動いていたコードが、関数の本体のどこかに代入文を加えるという変更をしたら UnboundLocalError を出すのには驚くかもしれません。"
#: ../../faq/programming.rst:284
msgid "This code:"
msgstr "このコード:"
#: ../../faq/programming.rst:292
msgid "works, but this code:"
msgstr "は動きますが、このコード:"
#: ../../faq/programming.rst:299
msgid "results in an UnboundLocalError:"
msgstr "は UnboundLocalError になります:"
#: ../../faq/programming.rst:306
msgid ""
"This is because when you make an assignment to a variable in a scope, that "
"variable becomes local to that scope and shadows any similarly named "
"variable in the outer scope. Since the last statement in foo assigns a new "
"value to ``x``, the compiler recognizes it as a local variable. "
"Consequently when the earlier ``print x`` attempts to print the "
"uninitialized local variable and an error results."
msgstr "これは、あるスコープの中で変数に代入を行うとき、その変数はそのスコープに対してローカルになり、外のスコープにある同じ名前の変数を隠すからです。 foo の最後の文が ``x`` に新しい値を代入しているので、コンパイラはこれをローカル変数であると認識します。その結果、先の ``print x`` が初期化されていないローカル変数を表示しようとして結果はエラーとなります。"
#: ../../faq/programming.rst:313
msgid ""
"In the example above you can access the outer scope variable by declaring it"
" global:"
msgstr "上の例では、グローバルであると宣言することで外のスコープにアクセスできます:"
#: ../../faq/programming.rst:324
msgid ""
"This explicit declaration is required in order to remind you that (unlike "
"the superficially analogous situation with class and instance variables) you"
" are actually modifying the value of the variable in the outer scope:"
msgstr "この明示的な宣言は (表面的には似ているクラスとインスタンス変数の例とは違って) あなたは実際は他のスコープの変数の値を変えようとしているのだ、ということを知らせるのに必要です:"
#: ../../faq/programming.rst:333
msgid "What are the rules for local and global variables in Python?"
msgstr "Python のローカルとグローバル変数のルールは何ですか?"
#: ../../faq/programming.rst:335
msgid ""
"In Python, variables that are only referenced inside a function are "
"implicitly global. If a variable is assigned a value anywhere within the "
"function's body, it's assumed to be a local unless explicitly declared as "
"global."
msgstr "Python では、関数の中で参照のみされる変数は暗黙のうちにグローバルになります。関数の本体のどこかで値が変数に代入されたなら、それは明示的にグローバルであると宣言されない限り、ローカルであるとみなされます。"
#: ../../faq/programming.rst:339
msgid ""
"Though a bit surprising at first, a moment's consideration explains this. "
"On one hand, requiring :keyword:`global` for assigned variables provides a "
"bar against unintended side-effects. On the other hand, if ``global`` was "
"required for all global references, you'd be using ``global`` all the time."
" You'd have to declare as global every reference to a built-in function or "
"to a component of an imported module. This clutter would defeat the "
"usefulness of the ``global`` declaration for identifying side-effects."
msgstr "最初はちょっと驚くでしょうが、少し考えると納得できます。一方では、代入された変数に :keyword:`global` を要求することで、意図しない副作用を防げます。他方では、グローバルな参照の度に ``global`` が要求されてしまうと、 ``global`` を使ってばかりになってしまいます。ビルトイン関数やインポートされたモジュールの内容を参照するたびにグローバル宣言をしなければならないのです。その乱雑さは副作用を特定するための ``global`` 宣言の便利さよりも重大です。"
#: ../../faq/programming.rst:349
msgid ""
"Why do lambdas defined in a loop with different values all return the same "
"result?"
msgstr "ループの中で異なる値で定義されたラムダ式が、同じ値を返すのはなぜですか?"
#: ../../faq/programming.rst:351
msgid ""
"Assume you use a for loop to define a few different lambdas (or even plain "
"functions), e.g.::"
msgstr "for ループを使って、少しずつ異なるラムダを定義 (もしくは簡単な関数) するとします。例えば::"
#: ../../faq/programming.rst:358
msgid ""
"This gives you a list that contains 5 lambdas that calculate ``x**2``. You "
"might expect that, when called, they would return, respectively, ``0``, "
"``1``, ``4``, ``9``, and ``16``. However, when you actually try you will "
"see that they all return ``16``::"
msgstr "これで ``x**2`` を計算する 5 つのラムダのリストが得られます。それらを呼び出したとき、それぞれ ``0``、``1``、``4``、``9``、``16`` を返すと予想するかもしれません。しかし実際にやってみると、全て ``16`` が返ってくるのを目にするでしょう::"
#: ../../faq/programming.rst:368
msgid ""
"This happens because ``x`` is not local to the lambdas, but is defined in "
"the outer scope, and it is accessed when the lambda is called --- not when "
"it is defined. At the end of the loop, the value of ``x`` is ``4``, so all "
"the functions now return ``4**2``, i.e. ``16``. You can also verify this by"
" changing the value of ``x`` and see how the results of the lambdas change::"
msgstr "これは、``x`` がラムダにとってのローカル変数ではなく外側のスコープで定義されていて、ラムダが定義されたときでなく呼び出されたときにアクセスされるために起こります。ループが終わった時点では ``x`` は ``4`` であり、従って、全ての関数は ``4**2`` つまり ``16`` を返します。このことは ``x`` の値を変えてみることで検証でき、ラムダの返り値がどのように変わるのか観察できます::"
#: ../../faq/programming.rst:378
msgid ""
"In order to avoid this, you need to save the values in variables local to "
"the lambdas, so that they don't rely on the value of the global ``x``::"
msgstr "これを避けるためには、グローバルの ``x`` の値に依存しないために、ラムダにとってのローカル変数に値を保存する必要があります::"
#: ../../faq/programming.rst:385
msgid ""
"Here, ``n=x`` creates a new variable ``n`` local to the lambda and computed "
"when the lambda is defined so that it has the same value that ``x`` had at "
"that point in the loop. This means that the value of ``n`` will be ``0`` in"
" the first lambda, ``1`` in the second, ``2`` in the third, and so on. "
"Therefore each lambda will now return the correct result::"
msgstr "ここで、``n=x`` は新しいラムダにとってのローカル変数 ``n`` を作成し、ラムダが定義されるときに計算されるので、ループのその時点での ``x`` と同じ値を持っています。これは、1 つ目のラムダでは ``n`` の値は ``0`` になり、2 つ目では ``1``、3 つ目では ``2`` 以下同様、となることを意味します。従って、それぞれのラムダは今や正しい値を返すようになりました::"
#: ../../faq/programming.rst:396
msgid ""
"Note that this behaviour is not peculiar to lambdas, but applies to regular "
"functions too."
msgstr "この動作はラムダに特有なものではなく、通常の関数にも適用されることに注意してください。"
#: ../../faq/programming.rst:401
msgid "How do I share global variables across modules?"
msgstr "グローバル変数をモジュール間で共有するにはどうしたらいいですか?"
#: ../../faq/programming.rst:403
msgid ""
"The canonical way to share information across modules within a single "
"program is to create a special module (often called config or cfg). Just "
"import the config module in all modules of your application; the module then"
" becomes available as a global name. Because there is only one instance of "
"each module, any changes made to the module object get reflected everywhere."
" For example:"
msgstr "一つのプログラムのモジュール間で情報を共有する正準な方法は、特別なモジュール (しばしば config や cfg と呼ばれる) を作ることです。単に設定モジュールをアプリケーションのすべてのモジュールにインポートしてください。このモジュールはグローバルな名前として使えます。それぞれのモジュールのただ一つのインスタンスがあるので、設定モジュールオブジェクトに対するいかなる変更も全体に反映されます。例えば:"
#: ../../faq/programming.rst:409
msgid "config.py::"
msgstr "config.py::"
#: ../../faq/programming.rst:413
msgid "mod.py::"
msgstr "mod.py::"
#: ../../faq/programming.rst:418
msgid "main.py::"
msgstr "main.py::"
#: ../../faq/programming.rst:424
msgid ""
"Note that using a module is also the basis for implementing the Singleton "
"design pattern, for the same reason."
msgstr "なお、同じ理由から、モジュールを使うということは、シングルトンデザインパターンを実装することの基礎でもあります。"
#: ../../faq/programming.rst:429
msgid "What are the \"best practices\" for using import in a module?"
msgstr "モジュールで import を使う際の「ベストプラクティス」は何ですか?"
#: ../../faq/programming.rst:431
msgid ""
"In general, don't use ``from modulename import *``. Doing so clutters the "
"importer's namespace, and makes it much harder for linters to detect "
"undefined names."
msgstr "一般的に ``from modulename import *`` を使ってはいけません。そのようにするとインポータの名前空間は汚染され、linter が未定義の名前を発見することが難しくなります。"
#: ../../faq/programming.rst:435
msgid ""
"Import modules at the top of a file. Doing so makes it clear what other "
"modules your code requires and avoids questions of whether the module name "
"is in scope. Using one import per line makes it easy to add and delete "
"module imports, but using multiple imports per line uses less screen space."
msgstr "モジュールはファイルの先頭でインポートしてください。これによってコードが必要とする他のモジュールが明確になり、モジュール名がスコープに含まれるかどうかに迷わなくなります。行に一つのインポートにすると、モジュールのインポートの追加と削除が容易になりますが、行に複数のインポートにすると画面の領域が少なく済みます。"
#: ../../faq/programming.rst:440
msgid "It's good practice if you import modules in the following order:"
msgstr "次の手順でモジュールをインポートするのが、良いプラクティスになります:"
#: ../../faq/programming.rst:442
msgid "standard library modules -- e.g. ``sys``, ``os``, ``getopt``, ``re``"
msgstr "標準ライブラリモジュール -- 例 ``sys``、``os``、``getopt``、``re``"
#: ../../faq/programming.rst:443
msgid ""
"third-party library modules (anything installed in Python's site-packages "
"directory) -- e.g. mx.DateTime, ZODB, PIL.Image, etc."
msgstr "サードパーティのライブラリモジュール (Python の site-packages ディレクトリにあるもの) -- 例 mx.DateTime、ZODB、PIL.Image、など"
#: ../../faq/programming.rst:445
msgid "locally-developed modules"
msgstr "自前で開発したモジュール"
#: ../../faq/programming.rst:447
msgid ""
"Only use explicit relative package imports. If you're writing code that's "
"in the ``package.sub.m1`` module and want to import ``package.sub.m2``, do "
"not just write ``import m2``, even though it's legal. Write ``from "
"package.sub import m2`` or ``from . import m2`` instead."
msgstr "明示的な相対インポートだけを使ってください。 ``package.sub.m1`` モジュールのコードを書いていて、 ``package.sub.m2`` をインポートしようとするときに ``import m2`` だけで済ませるのはやめてください。たとえそれが合法でも。代わりに ``from package.sub import m2`` または ``from . import m2`` と書いてください。"
#: ../../faq/programming.rst:452
msgid ""
"It is sometimes necessary to move imports to a function or class to avoid "
"problems with circular imports. Gordon McMillan says:"
msgstr "循環参照の問題を避けるために、インポートを関数やクラスに移すことが必要なときもあります。Gordon McMillan によれば:"
#: ../../faq/programming.rst:455
msgid ""
"Circular imports are fine where both modules use the \"import <module>\" "
"form of import. They fail when the 2nd module wants to grab a name out of "
"the first (\"from module import name\") and the import is at the top level."
" That's because names in the 1st are not yet available, because the first "
"module is busy importing the 2nd."
msgstr "循環参照は両方のモジュールが \"import <module>\" 形式のインポートを使っていれば大丈夫です。二つ目のモジュールが最初のモジュールから名前を確保しようとして (\"from module import name\")、そのインポートがトップレベルにあると駄目です。最初のモジュールが二つ目のモジュールをインポートするのに忙しくて、最初のモジュールの名前が利用可能になっていないからです。"
#: ../../faq/programming.rst:461
msgid ""
"In this case, if the second module is only used in one function, then the "
"import can easily be moved into that function. By the time the import is "
"called, the first module will have finished initializing, and the second "
"module can do its import."
msgstr "この状況では、二つ目のモジュールが一つの関数の中でのみ使われているならば、そのインポートは簡単に関数の中に移せます。インポートが呼ばれたとき、最初のモジュールは初期化を完了していて、二つ目のモジュールは自分のインポートをできます。"
#: ../../faq/programming.rst:466
msgid ""
"It may also be necessary to move imports out of the top level of code if "
"some of the modules are platform-specific. In that case, it may not even be"
" possible to import all of the modules at the top of the file. In this "
"case, importing the correct modules in the corresponding platform-specific "
"code is a good option."
msgstr "プラットフォーム依存のモジュールがあるときには、インポートをトップレベルの外に動かすことも必要です。この場合、ファイルの先頭ではすべてのモジュールをインポートすることさえできないかもしれません。この場合は、対応するプラットフォームに合わせたコードで正しいモジュールをインポートすることを選ぶと良いです。"
#: ../../faq/programming.rst:471
msgid ""
"Only move imports into a local scope, such as inside a function definition, "
"if it's necessary to solve a problem such as avoiding a circular import or "
"are trying to reduce the initialization time of a module. This technique is"
" especially helpful if many of the imports are unnecessary depending on how "
"the program executes. You may also want to move imports into a function if "
"the modules are only ever used in that function. Note that loading a module"
" the first time may be expensive because of the one time initialization of "
"the module, but loading a module multiple times is virtually free, costing "
"only a couple of dictionary lookups. Even if the module name has gone out "
"of scope, the module is probably available in :data:`sys.modules`."
msgstr "循環参照の問題を避けたりモジュールの初期化にかかる時間を減らしたりしたいなら、単にインポートを関数定義の中などのローカルなスコープに移してください。この手法は多くのインポートがプログラムがどのように実行されるかに依存しなくてよいときに特に有効です。ある関数の中でのみモジュールが使われるのなら、インポートをその関数の中に移すことを考えてもいいでしょう。なお、モジュールを読み込む最初の回はモジュールの初期化の時間のために高価になりえますが、複数回目にモジュールを読み込むのは事実上無料、辞書探索の数回のコストだけで済みます。モジュール名がスコープから外れてさえ、そのモジュールはおそらく :data:`sys.modules` から利用できるでしょう。"
#: ../../faq/programming.rst:484
msgid "Why are default values shared between objects?"
msgstr "なぜオブジェクト間でデフォルト値が共有されるのですか?"
#: ../../faq/programming.rst:486
msgid ""
"This type of bug commonly bites neophyte programmers. Consider this "
"function::"
msgstr "この種のバグがよく初心者プログラマに噛み付きます。この関数を考えてみてください::"
#: ../../faq/programming.rst:493
msgid ""
"The first time you call this function, ``mydict`` contains a single item. "
"The second time, ``mydict`` contains two items because when ``foo()`` begins"
" executing, ``mydict`` starts out with an item already in it."
msgstr "初めてこの関数を呼び出した時、``mydict`` には一つの要素があります。二回目には、``foo()`` が実行されるときに ``mydict`` には初めから一つの要素をすでに持っているので、``mydict`` には二つの要素があります。"
#: ../../faq/programming.rst:497
msgid ""
"It is often expected that a function call creates new objects for default "
"values. This is not what happens. Default values are created exactly once, "
"when the function is defined. If that object is changed, like the "
"dictionary in this example, subsequent calls to the function will refer to "
"this changed object."
msgstr "関数の呼び出しによって、デフォルトの値に対する新しいオブジェクトが作られるのだと予想しがちです。実はそうなりません。デフォルト値は、関数が定義されたときに一度だけ生成されます。この例の辞書のように、そのオブジェクトが変更されたとき、その後の関数の呼び出しは変更後のオブジェクトを参照します。"
#: ../../faq/programming.rst:502
msgid ""
"By definition, immutable objects such as numbers, strings, tuples, and "
"``None``, are safe from change. Changes to mutable objects such as "
"dictionaries, lists, and class instances can lead to confusion."
msgstr "定義の時に、数、文字列、タプル、``None`` など、イミュータブルなオブジェクトを使うと変更される危険がありません。辞書、リスト、クラスインスタンスなどのミュータブルなオブジェクトは混乱のもとです。"
#: ../../faq/programming.rst:506
msgid ""
"Because of this feature, it is good programming practice to not use mutable "
"objects as default values. Instead, use ``None`` as the default value and "
"inside the function, check if the parameter is ``None`` and create a new "
"list/dictionary/whatever if it is. For example, don't write::"
msgstr "この性質から、ミュータブルなオブジェクトをデフォルト値として使わないプログラミング手法がいいです。代わりに、``None`` をデフォルト値に使い、そのパラメタが ``None`` である時にだけ、関数の内部で新しいリスト/辞書/その他をつくるようにしてください。例えば、こう書かずに::"
#: ../../faq/programming.rst:514
msgid "but::"
msgstr "代わりに::"
#: ../../faq/programming.rst:520
msgid ""
"This feature can be useful. When you have a function that's time-consuming "
"to compute, a common technique is to cache the parameters and the resulting "
"value of each call to the function, and return the cached value if the same "
"value is requested again. This is called \"memoizing\", and can be "
"implemented like this::"
msgstr "この性質が便利なこともあります。時間のかかる計算を行う関数があるときに使われる一般的な技法は、関数が呼び出されるごとにパラメタと結果の値をキャッシュし、再び同じ値が要求されたらキャッシュされた値を返すというものです。これは \"memoizing\" と呼ばれ、このように実装されます::"
#: ../../faq/programming.rst:535
msgid ""
"You could use a global variable containing a dictionary instead of the "
"default value; it's a matter of taste."
msgstr "デフォルト値の代わりに、辞書を含むグローバル変数も使えます。これは好みの問題です。"
#: ../../faq/programming.rst:540
msgid ""
"How can I pass optional or keyword parameters from one function to another?"
msgstr "オプションパラメータやキーワードパラメータを関数から関数へ渡すにはどうしたらいいですか?"
#: ../../faq/programming.rst:542
msgid ""
"Collect the arguments using the ``*`` and ``**`` specifiers in the "
"function's parameter list; this gives you the positional arguments as a "
"tuple and the keyword arguments as a dictionary. You can then pass these "
"arguments when calling another function by using ``*`` and ``**``::"
msgstr "関数のパラメータリストに引数を ``*`` と ``**`` 指定子 (specifier) で集めてください。そうすれば、固定引数をタプルとして、キーワード引数を辞書として得られます。これで、他の関数を呼び出すときに ``*`` と ``**`` を使ってそれらの引数を渡せます::"
#: ../../faq/programming.rst:553
msgid ""
"In the unlikely case that you care about Python versions older than 2.0, use"
" :func:`apply`::"
msgstr "あまりありませんが、Python の 2.0 以前のバージョンを考慮するときは、代わりに :func:`apply` を使ってください::"
#: ../../faq/programming.rst:570
msgid "What is the difference between arguments and parameters?"
msgstr "実引数と仮引数の違いは何ですか?"
#: ../../faq/programming.rst:572
msgid ""
":term:`Parameters <parameter>` are defined by the names that appear in a "
"function definition, whereas :term:`arguments <argument>` are the values "
"actually passed to a function when calling it. Parameters define what types"
" of arguments a function can accept. For example, given the function "
"definition::"
msgstr ":term:`仮引数 (parameter) <parameter>` は関数定義に表れる名前で定義されるのに対し、 :term:`実引数 (argument) <argument>` は関数を呼び出すときに実際に渡す値のことです。仮引数は関数が受け取ることの出来る実引数の型を定義します。例えば、以下のような関数定義があったとして::"
#: ../../faq/programming.rst:580
msgid ""
"*foo*, *bar* and *kwargs* are parameters of ``func``. However, when calling"
" ``func``, for example::"
msgstr "*foo*、*bar*、*kwargs* は ``func`` の仮引数です。一方、``func`` を呼び出すときには、例えば::"
#: ../../faq/programming.rst:585
msgid "the values ``42``, ``314``, and ``somevar`` are arguments."
msgstr "``42``、``314``、``somevar`` という値は実引数です。"
#: ../../faq/programming.rst:589
msgid "Why did changing list 'y' also change list 'x'?"
msgstr "なぜ list 'y' を変更すると list 'x' も変更されるのですか?"
#: ../../faq/programming.rst:591
msgid "If you wrote code like::"
msgstr "次のようなコードを書いたとします::"
#: ../../faq/programming.rst:601
msgid ""
"you might be wondering why appending an element to ``y`` changed ``x`` too."
msgstr "どうして ``y`` への要素の追加が ``x`` も変更してしまうのか疑問に思うかもしれません。 "
#: ../../faq/programming.rst:603
msgid "There are two factors that produce this result:"
msgstr "このような結果になる2つの要因があります:"
#: ../../faq/programming.rst:605
msgid ""
"Variables are simply names that refer to objects. Doing ``y = x`` doesn't "
"create a copy of the list -- it creates a new variable ``y`` that refers to "
"the same object ``x`` refers to. This means that there is only one object "
"(the list), and both ``x`` and ``y`` refer to it."
msgstr "変数とは、単にオブジェクトを参照するための名前に過ぎません。 ``y = x`` とすることは、リストのコピーを作りません -- それは ``x`` が参照するのと同じオブジェクトを参照する新しい変数 ``y`` を作ります。つまり、あるのは一つのオブジェクト(この場合リスト)だけであって、 ``x`` と ``y`` の両方がそれを参照しているのです。"
#: ../../faq/programming.rst:609
msgid ""
"Lists are :term:`mutable`, which means that you can change their content."
msgstr "リストは :term:`mutable` です。内容を変更出来る、ということです。"
#: ../../faq/programming.rst:611
msgid ""
"After the call to :meth:`~list.append`, the content of the mutable object "
"has changed from ``[]`` to ``[10]``. Since both the variables refer to the "
"same object, using either name accesses the modified value ``[10]``."
msgstr ":meth:`~list.append` 呼び出しの後、ミュータブルオブジェクトの内容が ``[]`` から ``[10]`` に変わります。 変数が同じオブジェクトを参照しているので、どちらの名前であっても変更された値 ``[10]`` にアクセスします。"
#: ../../faq/programming.rst:615
msgid "If we instead assign an immutable object to ``x``::"
msgstr "代わりに ``x`` にイミュータブルを代入すると::"
#: ../../faq/programming.rst:625
msgid ""
"we can see that in this case ``x`` and ``y`` are not equal anymore. This is"
" because integers are :term:`immutable`, and when we do ``x = x + 1`` we are"
" not mutating the int ``5`` by incrementing its value; instead, we are "
"creating a new object (the int ``6``) and assigning it to ``x`` (that is, "
"changing which object ``x`` refers to). After this assignment we have two "
"objects (the ints ``6`` and ``5``) and two variables that refer to them "
"(``x`` now refers to ``6`` but ``y`` still refers to ``5``)."
msgstr "この場合ご覧の通り ``x`` と ``y`` はまったく同じではありませんね。これは整数が :term:`immutable` だからで、 ``x = x + 1`` は整数の ``5`` の値を変更しているのではありません; 代わりに新しいオブジェクト(整数 ``6``)を作って ``x`` に代入しています (つまり ``x`` が参照するオブジェクトが変わります)。この代入の後では私たちは 2 つのオブジェクト(整数の ``6`` と ``5``)を持っていて、2 つの変数はそれらを参照しています(``x`` はいまや ``6`` を参照していますが ``y`` は ``5`` を参照したままです)。"
#: ../../faq/programming.rst:633
msgid ""
"Some operations (for example ``y.append(10)`` and ``y.sort()``) mutate the "
"object, whereas superficially similar operations (for example ``y = y + "
"[10]`` and ``sorted(y)``) create a new object. In general in Python (and in"
" all cases in the standard library) a method that mutates an object will "
"return ``None`` to help avoid getting the two types of operations confused."
" So if you mistakenly write ``y.sort()`` thinking it will give you a sorted"
" copy of ``y``, you'll instead end up with ``None``, which will likely cause"
" your program to generate an easily diagnosed error."
msgstr "ある演算 (たとえば ``y.append(10)``, ``y.sort()``) がオブジェクトを変更する一方で、外見上は似た演算 (たとえば ``y = y + [10]``, ``sorted(y)``) は新しいオブジェクトを作ります。Python では一般に (そして標準ライブラリの全てのケースで)、このような 2 つのタイプの演算にまつわる混乱を避けるために、オブジェクトを変更するメソッドは ``None`` を返します。ですからもしあなたが誤って ``y`` の複製の並び替えをするつもりで ``y.sort()`` と書いた場合に結果手にするのは ``None`` でしょうから、あなたのプログラムは簡単に診断出来るエラーを起こすでしょう。"
#: ../../faq/programming.rst:642
msgid ""
"However, there is one class of operations where the same operation sometimes"
" has different behaviors with different types: the augmented assignment "
"operators. For example, ``+=`` mutates lists but not tuples or ints "
"(``a_list += [1, 2, 3]`` is equivalent to ``a_list.extend([1, 2, 3])`` and "
"mutates ``a_list``, whereas ``some_tuple += (1, 2, 3)`` and ``some_int += "
"1`` create new objects)."
msgstr "しかしながら、同じ操作が型ごとに異なる振る舞いをする演算の種類が一つあります: 累算代入演算です。例えば ``+=`` はリストを変更しますが、タプルや整数は変更しません(``a_list += [1, 2, 3]`` は ``a_list.extend([1, 2, 3])`` と同じ意味で、そして ``a_list`` を変更しますが、 ``some_tuple += (1, 2, 3)`` と ``some_int += 1`` は新しいオブジェクトを作ります)。"
#: ../../faq/programming.rst:649
msgid "In other words:"
msgstr "言い換えると:"
#: ../../faq/programming.rst:651
msgid ""
"If we have a mutable object (:class:`list`, :class:`dict`, :class:`set`, "
"etc.), we can use some specific operations to mutate it and all the "
"variables that refer to it will see the change."
msgstr "ミュータブルなオブジェクト(:class:`list`, :class:`dict`, :class:`set`, 等)を持っている場合、私たちはその内容を変更するある種の演算を使うことが出来、それを参照している全ての変数はその変化を見ることになるでしょう。"
#: ../../faq/programming.rst:654
msgid ""
"If we have an immutable object (:class:`str`, :class:`int`, :class:`tuple`, "
"etc.), all the variables that refer to it will always see the same value, "
"but operations that transform that value into a new value always return a "
"new object."
msgstr "イミュータブルなオブジェクト(:class:`str`, :class:`int`, :class:`tuple`, 等)を持っている場合、それを参照している全ての変数は同じ値を参照しているでしょうが、持っている値を新しい値に変換する演算はいつでも新しいオブジェクトを返します。"
#: ../../faq/programming.rst:659
msgid ""
"If you want to know if two variables refer to the same object or not, you "
"can use the :keyword:`is` operator, or the built-in function :func:`id`."
msgstr "2つの変数が同じオブジェクトを参照しているかどうかが知りたければ、 :keyword:`is` オペレータまたは組み込み関数 :func:`id` が使えます。"
#: ../../faq/programming.rst:664
msgid "How do I write a function with output parameters (call by reference)?"
msgstr "パラメータを出力する関数 (参照渡し) はどのように書きますか?"
#: ../../faq/programming.rst:666
msgid ""
"Remember that arguments are passed by assignment in Python. Since "
"assignment just creates references to objects, there's no alias between an "
"argument name in the caller and callee, and so no call-by-reference per se."
" You can achieve the desired effect in a number of ways."
msgstr "前提として、Python では引数は代入によって渡されます。代入はオブジェクトへの参照を作るだけなので、呼び出し元と呼び出し先にある引数名の間にエイリアスはありませんし、参照渡しそれ自体はありません。望む効果を得るためには幾つかの方法があります。"
#: ../../faq/programming.rst:671
msgid "By returning a tuple of the results::"
msgstr "結果のタプルを返すことによって::"
#: ../../faq/programming.rst:682
msgid "This is almost always the clearest solution."
msgstr "これはたいてい一番明確な方法です。"
#: ../../faq/programming.rst:684
msgid ""
"By using global variables. This isn't thread-safe, and is not recommended."
msgstr "グローバル変数を使って。これはスレッドセーフでないので、推奨されません。"
#: ../../faq/programming.rst:686
msgid "By passing a mutable (changeable in-place) object::"
msgstr "ミュータブルな (インプレースに変更可能な) オブジェクトを渡すことによって::"
#: ../../faq/programming.rst:696
msgid "By passing in a dictionary that gets mutated::"
msgstr "変更される辞書に渡すことによって::"
#: ../../faq/programming.rst:706
msgid "Or bundle up values in a class instance::"
msgstr "または、クラスインスタンスに値を同梱することによって::"
#: ../../faq/programming.rst:722
msgid "There's almost never a good reason to get this complicated."
msgstr "このような複雑なことをする理由はめったに無いでしょう。"
#: ../../faq/programming.rst:724
msgid "Your best choice is to return a tuple containing the multiple results."
msgstr "一番の選択は、複数の結果を含むタプルを返すことです。"
#: ../../faq/programming.rst:728
msgid "How do you make a higher order function in Python?"
msgstr "Python で高次関数はどのようにつくりますか?"
#: ../../faq/programming.rst:730
msgid ""
"You have two choices: you can use nested scopes or you can use callable "
"objects. For example, suppose you wanted to define ``linear(a,b)`` which "
"returns a function ``f(x)`` that computes the value ``a*x+b``. Using nested"
" scopes::"
msgstr "二つの方法があります: ネストされたスコープを使う方法と、呼び出し可能オブジェクトを使う方法です。例えば、``a*x+b`` の値を計算する ``f(x)`` 関数を返す ``linear(a,b)`` を定義したいとします。ネストされたスコープを使うと::"
#: ../../faq/programming.rst:739
msgid "Or using a callable object::"
msgstr "また、呼び出し可能オブジェクトを使うと::"
#: ../../faq/programming.rst:749
msgid "In both cases, ::"
msgstr "どちらの場合でも、 ::"
#: ../../faq/programming.rst:753
msgid "gives a callable object where ``taxes(10e6) == 0.3 * 10e6 + 2``."
msgstr "とすれば、``taxes(10e6) == 0.3 * 10e6 + 2`` となるような呼び出し可能オブジェクトを得られます。"
#: ../../faq/programming.rst:755
msgid ""
"The callable object approach has the disadvantage that it is a bit slower "
"and results in slightly longer code. However, note that a collection of "
"callables can share their signature via inheritance::"
msgstr "呼び出し可能オブジェクトを使う方法は、少し遅くなり、わずかにコードが長くなるという短所があります。ですが、継承を使ってコーラブル同士で記号を共有することもできます::"
#: ../../faq/programming.rst:764
msgid "Object can encapsulate state for several methods::"
msgstr "オブジェクトはいくつかのメソッドに状態をカプセル化できます::"
#: ../../faq/programming.rst:782
msgid ""
"Here ``inc()``, ``dec()`` and ``reset()`` act like functions which share the"
" same counting variable."
msgstr "ここで、``inc()``、``dec()``、``reset()`` は同じカウント変数を共有する関数のようにふるまいます。"
#: ../../faq/programming.rst:787
msgid "How do I copy an object in Python?"
msgstr "Python のオブジェクトはどのようにコピーしますか?"
#: ../../faq/programming.rst:789
msgid ""
"In general, try :func:`copy.copy` or :func:`copy.deepcopy` for the general "
"case. Not all objects can be copied, but most can."
msgstr "一般的に、普通は :func:`copy.copy` や :func:`copy.deepcopy` を試してください。何でもコピーできるとは限りませんが、たいていはできます。"
#: ../../faq/programming.rst:792
msgid ""
"Some objects can be copied more easily. Dictionaries have a "
":meth:`~dict.copy` method::"
msgstr "もっと簡単にコピーできるオブジェクトもあります。辞書には :meth:`~dict.copy` メソッドがあります::"
#: ../../faq/programming.rst:797
msgid "Sequences can be copied by slicing::"
msgstr "シーケンスはスライシングでコピーできます::"
#: ../../faq/programming.rst:803
msgid "How can I find the methods or attributes of an object?"
msgstr "オブジェクトのメソッドや属性はどのように見つけますか?"
#: ../../faq/programming.rst:805
msgid ""
"For an instance x of a user-defined class, ``dir(x)`` returns an "
"alphabetized list of the names containing the instance attributes and "
"methods and attributes defined by its class."
msgstr "ユーザー定義クラスのインスタンス x で、``dir(x)`` はインスタンス属性とそのクラスで定義されたメソッドや属性を含む名前のアルファベット順リストを返します。"
#: ../../faq/programming.rst:811
msgid "How can my code discover the name of an object?"
msgstr "コードはどのようにオブジェクトの名前を見つけるのですか?"
#: ../../faq/programming.rst:813
msgid ""
"Generally speaking, it can't, because objects don't really have names. "
"Essentially, assignment always binds a name to a value; The same is true of "
"``def`` and ``class`` statements, but in that case the value is a callable. "
"Consider the following code::"
msgstr "概して、オブジェクトは本当は名前を持たないので、見つけることはできません。本質的には、代入とはいつも値に名前を束縛することです。``def`` と ``class`` 文も同じですが、この場合は値はコーラブルです。以下のコードを考えてみましょう::"
#: ../../faq/programming.rst:829
msgid ""
"Arguably the class has a name: even though it is bound to two names and "
"invoked through the name B the created instance is still reported as an "
"instance of class A. However, it is impossible to say whether the "
"instance's name is a or b, since both names are bound to the same value."
msgstr "おそらく、このクラスには名前があります。このクラスは二つの名前に縛られて、名前 B を通して呼び出されますが、それでもクラス A のインスタンスとして報告されるのです。しかし、両方の名前が同じ値に束縛されている以上、このインスタンスの名前が a か b か決めることはできないのです。"
#: ../../faq/programming.rst:834
msgid ""
"Generally speaking it should not be necessary for your code to \"know the "
"names\" of particular values. Unless you are deliberately writing "
"introspective programs, this is usually an indication that a change of "
"approach might be beneficial."
msgstr "概して、コードにとってある値の「名前を知っている」事は重要ではありません。あなたがわざと内省的なコードを書いているのでない限り、方針を変えた方がいいかもしれないということになるでしょう。"
#: ../../faq/programming.rst:839
msgid ""
"In comp.lang.python, Fredrik Lundh once gave an excellent analogy in answer "
"to this question:"
msgstr "comp.lang.python で、Fredrik Lundh はこの問題の答えとして素晴らしい喩えをしてくれました:"
#: ../../faq/programming.rst:842
msgid ""
"The same way as you get the name of that cat you found on your porch: the "
"cat (object) itself cannot tell you its name, and it doesn't really care -- "
"so the only way to find out what it's called is to ask all your neighbours "
"(namespaces) if it's their cat (object)..."
msgstr "玄関にいた猫の名前を知るのと同じ方法です: その猫 (オブジェクト) 自体はその名前を言うことができないし、それは実は問題ではありません -- その猫が何と呼ばれているかを知る唯一の方法は、すべての隣人 (名前空間) にその猫 (オブジェクト) が何と呼ばれているかを聞くことです。"
#: ../../faq/programming.rst:847
msgid ""
"....and don't be surprised if you'll find that it's known by many names, or "
"no name at all!"
msgstr "……そして、その猫が沢山の名前で知られていたり、逆に全く名前が無かったりしても驚かないでください!"
#: ../../faq/programming.rst:852
msgid "What's up with the comma operator's precedence?"
msgstr "カンマ演算子はなぜ優先されるのですか?"
#: ../../faq/programming.rst:854
msgid "Comma is not an operator in Python. Consider this session::"
msgstr "カンマは Python では演算子ではありません。このセッションを考えてください::"