8000 docs(library/argparse.po): up to line 1682 · SkyLull/python-docs-zh-tw@d4d5135 · GitHub
[go: up one dir, main page]

Skip to content

Commit d4d5135

Browse files
committed
docs(library/argparse.po): up to line 1682
1 parent f114db2 commit d4d5135

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

library/argparse.po

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,7 +1447,8 @@ msgid ""
14471447
"BooleanOptionalAction` is available in :mod:`!argparse` and adds support for "
14481448
"boolean actions such as ``--foo`` and ``--no-foo``::"
14491449
msgstr ""
1450-
""
1450+
"你也可以透過傳入一個 :class:`Action` 子類別或其他任意時做了相同界面的物件來指定一個任意動作。:class:`!"
1451+
"BooleanOptionalAction` 在 :mod:`!argparse` 中可用,且支援如 ``--foo`` 與 ``--no-foo`` 樣式的布林動作:::"
14511452

14521453
#: ../../library/argparse.rst:745
14531454
msgid ""
@@ -1469,10 +1470,12 @@ msgid ""
14691470
"overriding the :meth:`!__call__` method and optionally the :meth:`!__init__` "
14701471
"and :meth:`!format_usage` methods."
14711472
msgstr ""
1473+
"擴充 :class:`Action`,覆寫其中的 :meth:`!__call__` 方法、以及非必要的 :meth:`!__init__` 、"
1474+
":meth:`!format_usage` 等方法是目前自創一個動作時的推薦方式。"
14721475

14731476
#: ../../library/argparse.rst:757
14741477
msgid "An example of a custom action::"
1475-
msgstr ""
1478+
msgstr "以下是一個自訂動作的範例:::"
14761479

14771480
#: ../../library/argparse.rst:759
14781481
msgid ""
@@ -1494,10 +1497,27 @@ msgid ""
14941497
">>> args\n"
14951498
"Namespace(bar='1', foo='2')"
14961499
msgstr ""
1500+
">>> class FooAction(argparse.Action):\n"
1501+
"... def __init__(self, option_strings, dest, nargs=None, **kwargs):\n"
1502+
"... if nargs is not None:\n"
1503+
"... raise ValueError(\"不允許 nargs 有值\")\n"
1504+
"... super().__init__(option_strings, dest, **kwargs)\n"
1505+
"... def __call__(self, parser, namespace, values, option_string=None):\n"
1506+
"... print('%r %r %r' % (namespace, values, option_string))\n"
1507+
"... setattr(namespace, self.dest, values)\n"
1508+
"...\n"
1509+
">>> parser = argparse.ArgumentParser()\n"
1510+
">>> parser.add_argument('--foo', action=FooAction)\n"
1511+
">>> parser.add_argument('bar', action=FooAction)\n"
1512+
">>> args = parser.parse_args('1 --foo 2'.split())\n"
1513+
"Namespace(bar=None, foo=None) '1' None\n"
1514+
"Namespace(bar='1', foo=None) '2' '--foo'\n"
1515+
">>> args\n"
1516+
"Namespace(bar='1', foo='2')"
14971517

14981518
#: ../../library/argparse.rst:777
14991519
msgid "For more details, see :class:`Action`."
1500-
msgstr "更多詳情請見 :class:`Action`。"
1520+
msgstr "詳情請見 :class:`Action`。"
15011521

15021522
#: ../../library/ar 8000 gparse.rst:783
15031523
msgid "nargs"
@@ -1511,12 +1531,15 @@ msgid ""
15111531
"action. See also :ref:`specifying-ambiguous-arguments`. The supported values "
15121532
"are:"
15131533
msgstr ""
1534+
":class:`ArgumentParser` 一般來說會為每一個命令列選項分配一個動作。 ``nargs`` 關鍵字引數可使多個選項共用同一個動作。"
1535+
"請另參閱 :ref:`specifying-ambiguous-arguments`。 本引數支援的值有:"
15141536

15151537
#: ../../library/argparse.rst:790
15161538
msgid ""
15171539
"``N`` (an integer). ``N`` arguments from the command line will be gathered "
15181540
"together into a list. For example::"
15191541
msgstr ""
1542+
"``N`` (一個整數。) ``N`` 個來自命令的引數會被集成至一個串列(list)中。例如:::"
15201543

15211544
#: ../../library/argparse.rst:793
15221545
msgid ""
@@ -1537,6 +1560,7 @@ msgid ""
15371560
"Note that ``nargs=1`` produces a list of one item. This is different from "
15381561
"the default, in which the item is produced by itself."
15391562
msgstr ""
1563+
"注意到 ``nargs=1`` 會產生含有一個元素的串列。與預設情況不同,預設情況下只會產生該選項的值本身。"
15401564

15411565
#: ../../library/argparse.rst:804
15421566
msgid ""
@@ -1547,6 +1571,8 @@ msgid ""
15471571
"by a command-line argument. In this case the value from const_ will be "
15481572
"produced. Some examples to illustrate this::"
15491573
msgstr ""
1574+
"``'?'``。 若情況允許,會從命令中消耗一個引數,並產生一個物件。如果沒有任何可用的引數, default_ 的預設值會被使用。"
1575+
"請注意,若是可選引數則還有其他可能—如果選項字串存在,但後方卻沒有任何來自命令的引數,則 const_ 中的值會被作為預設值使用。以下的範例展示了這個行為:::"
15501576

15511577
#: ../../library/argparse.rst:811
15521578
msgid ""
@@ -1575,6 +1601,7 @@ msgid ""
15751601
"One of the more common uses of ``nargs='?'`` is to allow optional input and "
15761602
"output files::"
15771603
msgstr ""
1604+
"其中一個最常見的 ``nargs='?'`` 用法是令指定輸入或輸出檔案的引數成為可選項:::"
15781605

15791606
#: ../../library/argparse.rst:824
15801607
msgid ""
@@ -1609,6 +1636,7 @@ msgid ""
16091636
"argument with ``nargs='*'``, but multiple optional arguments with "
16101637
"``nargs='*'`` is possible. For example::"
16111638
msgstr ""
1639+
"``'*'``。 所有可用的命令列引數都會被蒐集至一個串列(list)中。一般來說不會讓一個以上的選項具有 ``nargs='*'``,但確實可以做到讓數個選項同時具有 ``nargs='*'``。請見下例:::"
16121640

16131641
#: ../../library/argparse.rst:843
16141642
msgid ""
@@ -1632,6 +1660,8 @@ msgid ""
16321660
"a list. Additionally, an error message will be generated if there wasn't at "
16331661
"least one command-line argument present. For example::"
16341662
msgstr ""
1663+
"``'+'``. 與 ``'*'`` 很像,所有可用的命令列引數都會被收集到一個串列(llist)中。"
1664+
"除此之外,如果可用的引數少於一個則會產生一個錯誤訊息。請見下例:::"
16351665

16361666
#: ../../library/argparse.rst:856
16371667
msgid ""

0 commit comments

Comments
 (0)
0