@@ -31,16 +31,20 @@ msgid ""
31
31
"In Python, the special name ``__main__`` is used for two important "
32
32
"constructs:"
33
33
msgstr ""
34
+ "Python では、 ``__main__`` という特別な名前が次の二つの重要な用途で使われま"
35
+ "す:"
34
36
35
37
#: ../../library/__main__.rst:12
36
38
msgid ""
37
39
"the name of the top-level environment of the program, which can be checked "
38
40
"using the ``__name__ == '__main__'`` expression; and"
39
41
msgstr ""
42
+ "プログラムのトップレベル環境の名前。\n"
43
+ "``__name__ == '__main__'`` という式でチェックすることができる。"
40
44
41
45
#: ../../library/__main__.rst:14
42
46
msgid "the ``__main__.py`` file in Python packages."
43
- msgstr ""
47
+ msgstr "Python パッケージにおける ``__main__.py`` ファイル。 "
44
48
45
49
#: ../../library/__main__.rst:16
46
50
msgid ""
@@ -49,6 +53,12 @@ msgid ""
49
53
"detail below. If you're new to Python modules, see the tutorial section :"
50
54
"ref:`tut-modules` for an introduction."
51
55
msgstr ""
56
+ "どちらも Python のモジュールに関わる機能です。\n"
57
+ "1つ目はユーザーがどうモジュールを使うか、2つ目はモジュールとモジュールがど"
58
+ "うやりとりするかに関係します。\n"
59
+ "詳細は以下で説明します。\n"
60
+ "Python モジュールがどういうものかについては、 :ref:`tut-modules` を参照してく"
61
+ "ださい。"
52
62
53
63
#: ../../library/__main__.rst:25
54
64
msgid "``__name__ == '__main__'``"
@@ -60,22 +70,30 @@ msgid ""
60
70
"module's name. Usually, this is the name of the Python file itself without "
61
71
"the ``.py`` extension::"
62
72
msgstr ""
73
+ "Python モジュールやパッケージがインポートされるとき、 ``__name__`` の値はその"
74
+ "モジュールの名前となります。\n"
75
+ "通常、インポートされる Python ファイル自体のファイル名から拡張子``.py`` を除"
76
+ "いたものとなります::"
63
77
64
78
#: ../../library/__main__.rst:35
65
79
msgid ""
66
80
"If the file is part of a package, ``__name__`` will also include the parent "
67
81
"package's path::"
68
82
msgstr ""
83
+ "インポートされるファイルがパッケージの一部である場合は、 ``__name__`` にはそ"
84
+ "のパッケージのパスも含まれます::"
69
85
70
86
#: ../../library/__main__.rst:42
71
87
msgid ""
72
88
"However, if the module is executed in the top-level code environment, its "
73
89
"``__name__`` is set to the string ``'__main__'``."
74
90
msgstr ""
91
+ "しかし、モジュールがトップレベルのスクリプト環境で実行される場合は、 "
92
+ "``__name__`` が ``'__main__'`` という文字列になります。"
75
93
76
94
#: ../../library/__main__.rst:46
77
95
msgid "What is the \" top-level code environment\" ?"
78
- msgstr ""
96
+ msgstr "「トップレベルのスクリプト環境」とは "
79
97
80
98
#: ../../library/__main__.rst:48
81
99
msgid ""
@@ -88,36 +106,41 @@ msgstr ""
88
106
89
107
#: ../../library/__main__.rst:53
90
108
msgid "The top-level code environment can be:"
91
- msgstr ""
109
+ msgstr "以下のものがトップレベルのスクリプト環境となります: "
92
110
93
111
#: ../../library/__main__.rst:55
94
112
msgid "the scope of an interactive prompt::"
95
- msgstr ""
113
+ msgstr "インタラクティブプロンプトのスコープ:: "
96
114
97
115
#: ../../library/__main__.rst:60
98
116
msgid "the Python module passed to the Python interpreter as a file argument:"
99
- msgstr ""
117
+ msgstr "Python インタープリタにファイル引数として渡される Python モジュール: "
100
118
101
119
#: ../../library/__main__.rst:67
102
120
msgid ""
103
121
"the Python module or package passed to the Python interpreter with the :"
104
122
"option:`-m` argument:"
105
123
msgstr ""
124
+ "Python インタープリタにPython :option:`-m` オプションとして渡される Python モ"
125
+ "ジュールまたはパッケージ:"
106
126
107
127
#: ../../library/__main__.rst:75
108
128
msgid "Python code read by the Python interpreter from standard input:"
109
- msgstr ""
129
+ msgstr "標準入力から Python インタープリタが読み込む Python コード: "
110
130
111
131
#: ../../library/__main__.rst:86
112
132
msgid ""
113
133
"Python code passed to the Python interpreter with the :option:`-c` argument:"
114
134
msgstr ""
135
+ "Python インタープリタに :option:`-c` オプションで渡される Python コード:"
115
136
116
137
#: ../../library/__main__.rst:97
117
138
msgid ""
118
139
"In each of these situations, the top-level module's ``__name__`` is set to "
119
140
"``'__main__'``."
120
141
msgstr ""
142
+ "上記それぞれの場合で、トップレベルのモジュールの ``__name__`` の値が "
143
+ "``'__main__'`` となります。"
121
144
122
145
#: ../../library/__main__.rst:100
123
146
msgid ""
@@ -126,16 +149,22 @@ msgid ""
126
149
"idiom for conditionally executing code when the module is not initialized "
127
150
"from an import statement::"
128
151
msgstr ""
152
+ "これにより、 ``__name__`` をチェックすれば各モジュールは自分がトップレベル環"
153
+ "境で実行されているかどうかを知ることができます。\n"
154
+ "このことから、モジュールが import 文で初期化された場合以外の場合でのみコード"
155
+ "を実行するため、次のコードがしばしば用いられます::"
129
156
130
157
#: ../../library/__main__.rst:111
131
158
msgid ""
132
159
"For a more detailed look at how ``__name__`` is set in all situations, see "
133
160
"the tutorial section :ref:`tut-modules`."
134
161
msgstr ""
162
+ "あらゆる場合に ``__name__`` の値がどうセットされるのかについて、詳しくは"
163
+ "チュートリアルの :ref:`tut-modules` セクションを参照してください。"
135
164
136
165
#: ../../library/__main__.rst:116 ../../library/__main__.rst:239
137
166
msgid "Idiomatic Usage"
138
- msgstr ""
167
+ msgstr "通常の使われ方 "
139
168
140
169
#: ../../library/__main__.rst:118
141
170
msgid ""
@@ -144,13 +173,20 @@ msgid ""
144
173
"like this was imported from a different module, for example to unit test it, "
145
174
"the script code would unintentionally execute as well."
146
175
msgstr ""
176
+ "一部のモジュールでは、コマンドライン引数をパースしたり標準入力からデータを取"
177
+ "得したなど、スクリプト用途のみのコードが含まれています。\n"
178
+ "このようなモジュールが、例えばユニットテストのため、別のモジュールからイン"
179
+ "ポートされると、そのスクリプト用コードが意図に反して実行されてしまいます。"
147
180
148
181
#: ../../library/__main__.rst:123
149
182
msgid ""
150
183
"This is where using the ``if __name__ == '__main__'`` code block comes in "
151
184
"handy. Code within this block won't run unless the module is executed in the "
152
185
"top-level environment."
153
186
msgstr ""
187
+ "``if __name__ == '__main__'`` というコードは、このようなときに役立ちます。\n"
188
+ "このブロックの中にあるコードは、当該のモジュールがトップレベル環境で実行され"
189
+ "ていない限り、実行されません。"
154
190
155
191
#: ../../library/__main__.rst:127
156
192
msgid ""
@@ -168,6 +204,12 @@ msgid ""
168
204
"the global variable instead of a local name. A ``main`` function solves "
169
205
"this problem."
170
206
msgstr ""
207
+ "注意すべき点として、もし ``main`` 関数内のコードをカプセル化せず ``if "
208
+ "__name__ == '__main__'`` の下に直接書いた場合、 ``phrase`` 変数はモジュール全"
209
+ "体からグローバルにアクセスできてしまいます。\n"
210
+ "モジュール内の他の関数が意図せずローカル変数ではなくそのグローバル変数を使用"
211
+ "してしまう可能性があるため、ミスにつながります。\n"
212
+ "``main`` 関数を用意することでこの問題は解決できます。"
171
213
172
214
#: ../../library/__main__.rst:158
173
215
msgid ""
@@ -176,6 +218,11 @@ msgid ""
176
218
"imported, the ``echo`` and ``main`` functions will be defined, but neither "
177
219
"of them will be called, because ``__name__ != '__main__'``."
178
220
msgstr ""
221
+ "``main`` 関数を使うことのもう一つのメリットとして、 ``echo`` 関数が分離し、別"
222
+ "の場所からインポートできるようになることです。\n"
223
+ "``echo.py`` がインポートされるとき、 ``echo`` 関数と ``main`` 関数が定義され"
224
+ "ますが、 ``__name__ != '__main__'`` であるため、どちらの関数も呼び出されませ"
225
+ "ん。"
179
226
180
227
#: ../../library/__main__.rst:165
181
228
msgid "Packaging Considerations"
0 commit comments