@@ -424,15 +424,15 @@ msgstr ""
424424
425425#: ../../faq/design.rst:201
426426msgid "\" , \" .join(['1', '2', '4', '8', '16'])"
427- msgstr ""
427+ msgstr "\" , \" .join(['1', '2', '4', '8', '16']) "
428428
429429#: ../../faq/design.rst:203
430430msgid "which gives the result::"
431431msgstr "結果はこうなります::"
432432
433433#: ../../faq/design.rst:205
434434msgid "\" 1, 2, 4, 8, 16\" "
435- msgstr ""
435+ msgstr "\" 1, 2, 4, 8, 16 \" "
436436
437437#: ../../faq/design.rst:207
438438msgid "There are two common arguments against this usage."
@@ -465,7 +465,7 @@ msgstr ""
465465
466466#: ../../faq/design.rst:220
467467msgid "\" 1, 2, 4, 8, 16\" .split(\" , \" )"
468- msgstr ""
468+ msgstr "\" 1, 2, 4, 8, 16 \" .split( \" , \" ) "
469469
470470#: ../../faq/design.rst:222
471471msgid ""
@@ -511,6 +511,11 @@ msgid ""
511511" mydict[key] = getvalue(key)\n"
512512" value = mydict[key]"
513513msgstr ""
514+ "try:\n"
515+ " value = mydict[key]\n"
516+ "except KeyError:\n"
517+ " mydict[key] = getvalue(key)\n"
518+ " value = mydict[key]"
514519
515520#: ../../faq/design.rst:246
516521msgid ""
@@ -527,6 +532,10 @@ msgid ""
527532"else:\n"
528533" value = mydict[key] = getvalue(key)"
529534msgstr ""
535+ "if key in mydict:\n"
536+ " value = mydict[key]\n"
537+ "else:\n"
538+ " value = mydict[key] = getvalue(key)"
530539
531540#: ../../faq/design.rst:254
532541msgid ""
@@ -573,6 +582,12 @@ msgid ""
573582"func = functions[value]\n"
574583"func()"
575584msgstr ""
585+ "functions = {'a': function_1,\n"
586+ " 'b': function_2,\n"
587+ " 'c': self.method_1}\n"
588+ "\n"
589+ "func = functions[value]\n"
590+ "func()"
576591
577592#: ../../faq/design.rst:279
578593msgid ""
@@ -593,6 +608,14 @@ msgid ""
593608" method = getattr(self, method_name)\n"
594609" method()"
595610msgstr ""
611+ "class MyVisitor:\n"
612+ " def visit_a(self):\n"
613+ " ...\n"
614+ "\n"
615+ " def dispatch(self, value):\n"
616+ " method_name = 'visit_' + str(value)\n"
617+ " method = getattr(self, method_name)\n"
618+ " method()"
596619
597620#: ../../faq/design.rst:291
598621msgid ""
@@ -686,6 +709,10 @@ msgid ""
686709"an up-and-coming compiler of Python into C++ code, aiming to support the "
687710"full Python language."
688711msgstr ""
712+ "`Cython <https://cython.org/>`_ は、 オプションアノテーションを付けた 修正"
713+ "バージョンの Python から C 拡張 にコンパイルします。 `Nuitka <https://"
714+ "nuitka.net/>`_ は Python から C++ コードへの有望なコンパイラで、 フルセット"
715+ "の Python 言語サポートを目指しています。"
689716
690717#: ../../faq/design.rst:337
691718msgid "How does Python manage memory?"
@@ -701,12 +728,12 @@ msgid ""
701728"provides functions to perform a garbage collection, obtain debugging "
702729"statistics, and tune the collector's parameters."
703730msgstr ""
704- "Python のメモリ管理の詳細は実装に依ります。Python の標準の C 実装 :term:"
705- "`CPython` は参照カウントを使って、アクセスできないオブジェクトを探します。ま "
706- "た別のメカニズムを使って参照サイクルを集めます。これはサイクル検出アルゴリズ "
707- "ムを定期的に実行し、アクセスできないサイクルを探し、巻き込まれたオブジェクト "
708- "を削除します 。 :mod:`gc` モジュールの関数で、ガベージコレクションを実行し、デ "
709- "バッグ統計を取得し、コレクタのパラメタを変更できます 。"
731+ "Python のメモリ管理の詳細は実装に依ります。 Python の標準実装である :term:"
732+ "`CPython` は、参照カウントを使ってアクセスできない(訳注:参照されえない)オ "
733+ "ブジェクトを検出し、そして別の仕組みで参照サイクル(循環参照)を集めます。サ "
734+ "イクル検出アルゴリズムを定期的に実行し、アクセスできないサイクルを見つけて一 "
735+ "連のオブジェクトを削除します 。 :mod:`gc` モジュールは、ガベージコレクションの "
736+ "実行、デバッグ統計の取得、コレクタのパラメータ調整を行う関数を提供します 。"
710737
711738#: ../../faq/design.rst:347
712739msgid ""
@@ -716,6 +743,10 @@ msgid ""
716743"problems if your Python code depends on the behavior of the reference "
717744"counting implementation."
718745msgstr ""
746+ "ただし、他の実装( `Jython <https://www.jython.org>`_ や `PyPy <https://pypy."
747+ "org>`_ など)では、本格的なガベージコレクタのような別の仕組みを用いているかも"
748+ "しれません。 この違いは微妙な移植の問題を起こす可能性があります。もし あなた"
749+ "の Python コードが参照カウント実装の振る舞いに依存している場合には。"
719750
720751#: ../../faq/design.rst:353
721752msgid ""
@@ -731,6 +762,9 @@ msgid ""
731762" f = open(file)\n"
732763" c = f.read(1)"
733764msgstr ""
765+ "for file in very_long_list_of_files:\n"
766+ " f = open(file)\n"
767+ " c = f.read(1)"
734768
735769#: ../../faq/design.rst:360
736770msgid ""
@@ -760,6 +794,9 @@ msgid ""
760794" with open(file) as f:\n"
761795" c = f.read(1)"
762796msgstr ""
797+ "for file in very_long_list_of_files:\n"
798+ " with open(file) as f:\n"
799+ " c = f.read(1)"
763800
764801#: ../../faq/design.rst:375
765802msgid "Why doesn't CPython use a more traditional garbage collection scheme?"
@@ -996,6 +1033,8 @@ msgid ""
9961033"mydict = {[1, 2]: '12'}\n"
9971034"print(mydict[[1, 2]])"
9981035msgstr ""
1036+ "mydict = {[1, 2]: '12'}\n"
1037+ "print(mydict[[1, 2]])"
9991038
10001039#: ../../faq/design.rst:486
10011040msgid ""
@@ -1080,6 +1119,22 @@ msgid ""
10801119" result = (result % 7777777) + i * 333\n"
10811120" return result"
10821121msgstr ""
1122+ "class ListWrapper:\n"
1123+ " def __init__(self, the_list):\n"
1124+ " self.the_list = the_list\n"
1125+ "\n"
1126+ " def __eq__(self, other):\n"
1127+ " return self.the_list == other.the_list\n"
1128+ "\n"
1129+ " def __hash__(self):\n"
1130+ " l = self.the_list\n"
1131+ " result = 98767 - len(l)*555\n"
1132+ " for i, el in enumerate(l):\n"
1133+ " try:\n"
1134+ " result = result + (hash(el) % 9999999) * 1001 + i\n"
1135+ " except Exception:\n"
1136+ " result = (result % 7777777) + i * 333\n"
1137+ " return result"
10831138
10841139#: ../../faq/design.rst:530
10851140msgid ""
@@ -1151,6 +1206,8 @@ msgid ""
11511206"for key in sorted(mydict):\n"
11521207" ... # do whatever with mydict[key]..."
11531208msgstr ""
1209+ "for key in sorted(mydict):\n"
1210+ " ... # mydict[key] を使って何でもできる ..."
11541211
11551212#: ../../faq/design.rst:564
11561213msgid "How do you specify and enforce an interface spec in Python?"
@@ -1289,6 +1346,15 @@ msgid ""
12891346" pass\n"
12901347"..."
12911348msgstr ""
1349+ "class label(Exception): pass # declare a label\n"
1350+ "\n"
1351+ "try:\n"
1352+ " ...\n"
1353+ " if condition: raise label() # goto label\n"
1354+ " ...\n"
1355+ "except label: # goto 移動先\n"
1356+ " pass\n"
1357+ "..."
12921358
12931359#: ../../faq/design.rst:630
12941360msgid ""
@@ -1339,7 +1405,7 @@ msgstr ""
13391405
13401406#: ../../faq/design.rst:651
13411407msgid "f = open(\" /mydir/file.txt\" ) # works fine!"
1342- msgstr ""
1408+ msgstr "f = open( \" /mydir/file.txt \" ) # 正常に動く! "
13431409
13441410#: ../../faq/design.rst:653
13451411msgid ""
@@ -1354,6 +1420,9 @@ msgid ""
13541420"dir = r\"\\ this\\ is\\ my\\ dos\\ dir\\ \" [:-1]\n"
13551421"dir = \"\\\\ this\\\\ is\\\\ my\\\\ dos\\\\ dir\\\\\" "
13561422msgstr ""
1423+ "dir = r\"\\ this\\ is\\ my\\ dos\\ dir\" \"\\\\\" \n"
1424+ "dir = r\"\\ this\\ is\\ my\\ dos\\ dir\\ \" [:-1]\n"
1425+ "dir = \"\\\\ this\\\\ is\\\\ my\\\\ dos\\\\ dir\\\\\" "
13571426
13581427#: ../../faq/design.rst:661
13591428msgid "Why doesn't Python have a \" with\" statement for attribute assignments?"
@@ -1375,6 +1444,9 @@ msgid ""
13751444" a = 1 # equivalent to obj.a = 1\n"
13761445" total = total + 1 # obj.total = obj.total + 1"
13771446msgstr ""
1447+ "with obj:\n"
1448+ " a = 1 # これに相当: obj.a = 1\n"
1449+ " total = total + 1 # obj.total = obj.total + 1"
13781450
13791451#: ../../faq/design.rst:671
13801452msgid "In Python, such a construct would be ambiguous."
@@ -1414,6 +1486,9 @@ msgid ""
14141486" with a:\n"
14151487" print(x)"
14161488msgstr ""
1489+ "def foo(a):\n"
1490+ " with a:\n"
1491+ " print(x)"
14171492
14181493#: ../../faq/design.rst:690
14191494msgid ""
@@ -1445,6 +1520,9 @@ msgid ""
14451520"function(args).mydict[index][index].b = 42\n"
14461521"function(args).mydict[index][index].c = 63"
14471522msgstr ""
1523+ "function(args).mydict[index][index].a = 21\n"
1524+ "function(args).mydict[index][index].b = 42\n"
1525+ "function(args).mydict[index][index].c = 63"
14481526
14491527#: ../../faq/design.rst:703
14501528msgid "write this::"
@@ -1457,6 +1535,10 @@ msgid ""
14571535"ref.b = 42\n"
14581536"ref.c = 63"
14591537msgstr ""
1538+ "ref = function(args).mydict[index][index]\n"
1539+ "ref.a = 21\n"
1540+ "ref.b = 42\n"
1541+ "ref.c = 63"
14601542
14611543#: ../../faq/design.rst:710
14621544msgid ""
@@ -1474,7 +1556,7 @@ msgid ""
14741556"(see https://mail.python.org/pipermail/python-ideas/2016-May/040070.html)."
14751557msgstr ""
14761558"似た提案として、「先頭のドット」を使うなどして さらにコード量を減らす構文は、"
1477- "明白さを優先をして却下されました (https://mail.python.org/pipermail/python-"
1559+ "明白さを優先して却下されました (https://mail.python.org/pipermail/python-"
14781560"ideas/2016-May/040070.html 参照)。"
14791561
14801562#: ../../faq/design.rst:720
@@ -1511,6 +1593,8 @@ msgid ""
15111593"if a == b\n"
15121594" print(a)"
15131595msgstr ""
1596+ "if a == b\n"
1597+ " print(a)"
15141598
15151599#: ../../faq/design.rst:738
15161600msgid "versus ::"
@@ -1521,6 +1605,8 @@ msgid ""
15211605"if a == b:\n"
15221606" print(a)"
15231607msgstr ""
1608+ "if a == b:\n"
1609+ " print(a)"
15241610
15251611#: ../../faq/design.rst:743
15261612msgid ""
@@ -1563,6 +1649,12 @@ msgid ""
15631649" \" B\" : [6, 7], # last trailing comma is optional but good style\n"
15641650"}"
15651651msgstr ""
1652+ "[1, 2, 3,]\n"
1653+ "('a', 'b', 'c',)\n"
1654+ "d = {\n"
1655+ " \" A\" : [1, 5],\n"
1656+ " \" B\" : [6, 7], # 最後のカンマはオプションだが良いスタイル\n"
1657+ "}"
15661658
15671659#: ../../faq/design.rst:765
15681660msgid "There are several reasons to allow this."
@@ -1595,6 +1687,12 @@ msgid ""
15951687" \" fum\" \n"
15961688"]"
15971689msgstr ""
1690+ "x = [\n"
1691+ " \" fee\" ,\n"
1692+ " \" fie\" \n"
1693+ " \" foo\" ,\n"
1694+ " \" fum\" \n"
1695+ "]"
15981696
15991697#: ../../faq/design.rst:782
16001698msgid ""
0 commit comments