@@ -51,29 +51,32 @@ msgstr "ほとんどの中級から上級の Python 本もこの話題を扱っ
5151msgid "Can I create my own functions in C++?"
5252msgstr "C++ で独自の関数を作ることはできますか?"
5353
54- #: ../../faq/extending.rst:28
5554msgid ""
5655"Yes, using the C compatibility features found in C++. Place ``extern "
5756"\" C\" { ... }`` around the Python include files and put ``extern \" C\" `` "
5857"before each function that is going to be called by the Python interpreter. "
5958"Global or static C++ objects with constructors are probably not a good idea."
6059msgstr ""
61- "はい。C++ 内にある C 互換機能を使ってできます。 ``extern \" C\" { ... }`` で "
62- "Python のインクルードファイルを囲み、 ``extern \" C\" `` を Python インタプリタ"
63- "から呼ぶ各関数の前に置いてください。グローバルや静的な C++ オブジェクトの構造"
64- "体を持つものは良くないでしょう。"
60+ "はい。\n"
61+ "C++ 内にある C 互換機能を使ってできます。\n"
62+ "``extern \" C\" { ... }`` で Python のインクルードファイルを囲み、 ``extern "
63+ "\" C\" `` を Python インタプリタから呼ぶ各関数の前に置いてください。\n"
64+ "コンストラクタを持つグローバルな C++ オブジェクトや静的な C++ オブジェクトを"
65+ "使うのは、おそらく望ましくありません。"
6566
6667#: ../../faq/extending.rst:37
6768msgid "Writing C is hard; are there any alternatives?"
6869msgstr "C を書くのは大変です。他の方法はありませんか?"
6970
70- #: ../../faq/extending.rst:39
7171msgid ""
7272"There are a number of alternatives to writing your own C extensions, "
7373"depending on what you're trying to do. :ref:`Recommended third party tools "
7474"<c-api-tools>` offer both simpler and more sophisticated approaches to "
7575"creating C and C++ extensions for Python."
7676msgstr ""
77+ "何をしたいかに応じて、C 拡張を自分で書く以外にもいくつかの方法があります。\n"
78+ ":ref:`推奨されるサードパーティツール <c-api-tools>` には、Python の C/C++ 拡"
79+ "張をより簡単に作るものや、より高度な方法を提供するものがあります。"
7780
7881#: ../../faq/extending.rst:46
7982msgid "How can I execute arbitrary Python statements from C?"
@@ -185,22 +188,23 @@ msgstr ""
185188"す。パラメタは、オブジェクト、呼び出すメソッドの名前、 :c:func:"
186189"`Py_BuildValue` で使われるようなフォーマット文字列、そして引数です::"
187190
188- #: ../../faq/extending.rst:102
189191msgid ""
190192"PyObject *\n"
191193"PyObject_CallMethod(PyObject *object, const char *method_name,\n"
192194" const char *arg_format, ...);"
193195msgstr ""
196+ "PyObject *\n"
197+ "PyObject_CallMethod(PyObject *object, const char *method_name,\n"
198+ " const char *arg_format, ...);"
194199
195- #: ../../faq/extending.rst:106
196200msgid ""
197201"This works for any object that has methods -- whether built-in or user-"
198202"defined. You are responsible for eventually :c:func:`Py_DECREF`\\ 'ing the "
199203"return value."
200204msgstr ""
201- "これはメソッドを持ついかなるオブジェクトにも有効で、組み込みかユーザ定義かは "
202- "関係ありません。返り値に対して :c:func:`Py_DECREF` する必要があることもありま "
203- "す 。"
205+ "これは、組み込みかユーザー定義かを問わず、メソッドを持つ任意のオブジェクトに "
206+ "使えます。\n "
207+ "返り値を使い終わったら、呼び出し側で :c:func:`Py_DECREF` する責任があります 。"
204208
205209#: ../../faq/extending.rst:109
206210msgid ""
@@ -210,7 +214,6 @@ msgstr ""
210214"例えば、あるファイルオブジェクトの \" seek\" メソッドを 10, 0 を引数として呼ぶ"
211215"とき (ファイルオブジェクトのポインタを \" f\" とします)::"
212216
213- #: ../../faq/extending.rst:112
214217msgid ""
215218"res = PyObject_CallMethod(f, \" seek\" , \" (ii)\" , 10, 0);\n"
216219"if (res == NULL) {\n"
@@ -220,17 +223,24 @@ msgid ""
220223" Py_DECREF(res);\n"
221224"}"
222225msgstr ""
226+ "res = PyObject_CallMethod(f, \" seek\" , \" (ii)\" , 10, 0);\n"
227+ "if (res == NULL) {\n"
228+ " ... 例外が発生した場合の処理 ...\n"
229+ "}\n"
230+ "else {\n"
231+ " Py_DECREF(res);\n"
232+ "}"
223233
224- #: ../../faq/extending.rst:120
225234msgid ""
226235"Note that since :c:func:`PyObject_CallObject` *always* wants a tuple for the "
227236"argument list, to call a function without arguments, pass \" ()\" for the "
228237"format, and to call a function with one argument, surround the argument in "
229238"parentheses, e.g. \" (i)\" ."
230239msgstr ""
231240"なお、 :c:func:`PyObject_CallObject` の引数リストには *常に* タプルが必要で"
232- "す。関数を引数なしで呼び出すには、フォーマットに \" ()\" を渡し、関数を一つの"
233- "引数で呼び出すには、関数を括弧でくくって例えば \" (i)\" としてください。"
241+ "す。\n"
242+ "関数を引数なしで呼び出すには、フォーマットに \" ()\" を渡し、関数を一つの引数"
243+ "で呼び出すには、引数の書式を括弧で囲んで例えば \" (i)\" としてください。"
234244
235245#: ../../faq/extending.rst:127
236246msgid ""
@@ -256,7 +266,6 @@ msgstr ""
256266msgid "The easiest way to do this is to use the :class:`io.StringIO` class:"
257267msgstr "最も簡単な方法は、 :class:`io.StringIO` クラスを使うことです:"
258268
259- #: ../../faq/extending.rst:136
260269msgid ""
261270">>> import io, sys\n"
262271">>> sys.stdout = io.StringIO()\n"
@@ -266,12 +275,18 @@ msgid ""
266275"foo\n"
267276"hello world!"
268277msgstr ""
278+ ">>> import io, sys\n"
279+ ">>> sys.stdout = io.StringIO()\n"
280+ ">>> print('foo')\n"
281+ ">>> print('hello world!')\n"
282+ ">>> sys.stderr.write(sys.stdout.getvalue())\n"
283+ "foo\n"
284+ "hello world!"
269285
270286#: ../../faq/extending.rst:146
271287msgid "A custom object to do the same would look like this:"
272288msgstr "これと同じことをするカスタムオブジェクトは次のようになるでしょう:"
273289
274- #: ../../faq/extending.rst:148
275290msgid ""
276291">>> import io, sys\n"
277292">>> class StdoutCatcher(io.TextIOBase):\n"
@@ -288,6 +303,20 @@ msgid ""
288303"foo\n"
289304"hello world!"
290305msgstr ""
306+ ">>> import io, sys\n"
307+ ">>> class StdoutCatcher(io.TextIOBase):\n"
308+ "... def __init__(self):\n"
309+ "... self.data = []\n"
310+ "... def write(self, stuff):\n"
311+ "... self.data.append(stuff)\n"
312+ "...\n"
313+ ">>> import sys\n"
314+ ">>> sys.stdout = StdoutCatcher()\n"
315+ ">>> print('foo')\n"
316+ ">>> print('hello world!')\n"
317+ ">>> sys.stderr.write(''.join(sys.stdout.data))\n"
318+ "foo\n"
319+ "hello world!"
291320
292321#: ../../faq/extending.rst:167
293322msgid "How do I access a module written in Python from C?"
@@ -297,9 +326,8 @@ msgstr "C から Python で書かれたモジュールにアクセスするに
297326msgid "You can get a pointer to the module object as follows::"
298327msgstr "以下のようにモジュールオブジェクトへのポインタを得られます::"
299328
300- #: ../../faq/extending.rst:171
301329msgid "module = PyImport_ImportModule(\" <modulename>\" );"
302- msgstr ""
330+ msgstr "module = PyImport_ImportModule( \" <modulename> \" ); "
303331
304332#: ../../faq/extending.rst:173
305333msgid ""
@@ -323,9 +351,8 @@ msgstr ""
323351"これで、モジュールの属性 (つまり、モジュールで定義された任意の名前) に以下の"
324352"ようにアクセスできるようになります::"
325353
326- #: ../../faq/extending.rst:182
327354msgid "attr = PyObject_GetAttrString(module, \" <attrname>\" );"
328- msgstr ""
355+ msgstr "attr = PyObject_GetAttrString(module, \" <attrname> \" ); "
329356
330357#: ../../faq/extending.rst:184
331358msgid ""
@@ -379,13 +406,12 @@ msgstr ""
379406msgid "How do I debug an extension?"
380407msgstr "拡張をデバッグするにはどうしますか?"
381408
382- #: ../../faq/extending.rst:211
383409msgid ""
384410"When using GDB with dynamically loaded extensions, you can't set a "
385411"breakpoint in your extension until your extension is loaded."
386412msgstr ""
387413"動的にロードされた拡張に GDB を使うとき、拡張がロードされるまでブレークポイン"
388- "トを設定してはいけません 。"
414+ "トを設定できません 。"
389415
390416#: ../../faq/extending.rst:214
391417msgid "In your ``.gdbinit`` file (or interactively), add the command:"
@@ -417,19 +443,20 @@ msgstr ""
417443"Linux システムで Python モジュールをコンパイルしたいのですが、見つからない"
418444"ファイルがあります。なぜですか?"
419445
420- #: ../../faq/extending.rst:234
421446msgid ""
422447"Most packaged versions of Python omit some files required for compiling "
423448"Python extensions."
424449msgstr ""
450+ "パッケージとして配布されている Python の多くでは、Python 拡張のコンパイルに必"
451+ "要なファイルの一部が省かれています。"
425452
426- #: ../../faq/extending.rst:237
427453msgid "For Red Hat, install the python3-devel RPM to get the necessary files."
428454msgstr ""
455+ "Red Hat では、必要なファイルを入手するために python3-devel RPM をインストール"
456+ "してください。"
429457
430- #: ../../faq/extending.rst:239
431458msgid "For Debian, run ``apt-get install python3-dev``."
432- msgstr ""
459+ msgstr "Debian では ``apt-get install python3-dev`` を実行してください。 "
433460
434461#: ../../faq/extending.rst:242
435462msgid "How do I tell \" incomplete input\" from \" invalid input\" ?"
0 commit comments