@@ -1689,10 +1689,12 @@ msgid ""
1689
1689
"be produced. Actions that do not consume command-line arguments (e.g. "
1690
1690
"``'store_const'``) set ``nargs=0``."
1691
1691
msgstr ""
1692
+ "如果未提供關鍵字參數 ``nargs``,將消耗的參數量將取決於 action_ 的選擇。一般來說這代表會消耗一個命令列參數,並產生一個物件(而非串列)。"
1693
+ "不消耗命令列參數的動作將設定 ``nargs=0``。"
1692
1694
1693
1695
#: ../../library/argparse.rst:874
1694
1696
msgid "const"
1695
- msgstr ""
1697
+ msgstr "const "
1696
1698
1697
1699
#: ../../library/argparse.rst:876
1698
1700
msgid ""
@@ -1701,6 +1703,7 @@ msgid ""
1701
1703
"required for the various :class:`ArgumentParser` actions. The two most "
1702
1704
"common uses of it are:"
1703
1705
msgstr ""
1706
+ ":meth:`~ArgumentParser.add_argument` 的 ``const`` 參數用來保存許多 :class:`ArgumentParser` 動作使用到、但不從命令列參數讀取的常數。最常用到的兩個情況有:::"
1704
1707
1705
1708
#: ../../library/argparse.rst:880
1706
1709
msgid ""
@@ -1711,7 +1714,31 @@ msgid ""
1711
1714
"``const`` is not provided to :meth:`~ArgumentParser.add_argument`, it will "
1712
1715
"receive a default value of ``None``."
1713
1716
msgstr ""
1714
-
1717
+ "當設定 ``action='store_const'`` 或 ``action='append_const'`` 呼叫 :meth:`~ArgumentParser.add_argument` 時。這兩個動作會將 ``const`` 的值加入 :meth:"
1718
+ "`~ArgumentParser.parse_args` 方法所回傳物件的其中一個屬性。範例請見 action_ 的描述。"
1719
+ "如果沒有提供 ``const`` 值給 :meth:`~ArgumentParser.add_argument`,其預設值為 ``None``。"
1720
+
1721
+ # SkyLull: 痾,倒數第二段看不懂。我照實際操作的結果去翻。
1722
+ # Python 3.12.2 | packaged by Anaconda, Inc. | (main, Feb 27 2024, 17:35:02) [GCC 11.2.0] on linux
1723
+ # Type "help", "copyright", "credits" or "license" for more information.
1724
+ # >>> import argparse
1725
+ # >>> parser = argparse.ArgumentParser()
1726
+ # >>> parser.add_argument('--foo', const=42, nargs='?')
1727
+ # _StoreAction(option_strings=['--foo'], dest='foo', nargs='?', const=42, default=None, type=None, choices=None, required=False, help=None, metavar=None)
1728
+ # >>> parser.parse_args(["--foo", "52"])
1729
+ # Namespace(foo='52')
1730
+ # >>> parser.parse_args(["--foo"])
1731
+ # Namespace(foo=42)
1732
+ # >>> parser.parse_args([])
1733
+ # Namespace(foo=None)
1734
+ #
1735
+ # >>> parser = argparse.ArgumentParser()
1736
+ # >>> parser.add_argument('--foo', nargs='?')
1737
+ # _StoreAction(option_strings=['--foo'], dest='foo', nargs='?', const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None)
1738
+ # >>> parser.parse_args(["--foo"])
1739
+ # Namespace(foo=None)
1740
+ # >>> parser.parse_args([])
1741
+ # Namespace(foo=None)
1715
1742
#: ../../library/argparse.rst:888
1716
1743
msgid ""
1717
1744
"When :meth:`~ArgumentParser.add_argument` is called with option strings "
@@ -1721,16 +1748,21 @@ msgid ""
1721
1748
"command-line argument following it, the value of ``const`` will be assumed "
1722
1749
"to be ``None`` instead. See the nargs_ description for examples."
1723
1750
msgstr ""
1751
+ "當設定了選項字串(例如 ``-f`` 或 ``--foo``)給 :meth:`~ArgumentParser.add_argument` 且給予了 ``nargs='?'`` 時。"
1752
+ "將建立一個能接收零或一個參數的可選選項。在剖析命令時,如果選項後方沒有對應的參數,``const`` 的值將作為預設值,若未設定則預設為 ``None``。"
1753
+ "範例請見 nargs_ 的描述。"
1724
1754
1725
1755
#: ../../library/argparse.rst:895
1726
1756
msgid ""
1727
1757
"``const=None`` by default, including when ``action='append_const'`` or "
1728
1758
"``action='store_const'``."
1729
1759
msgstr ""
1760
+ "預設 ``const=None``,包含 ``action='append_const'`` 或"
1761
+ " ``action='store_const'`` 時。"
1730
1762
1731
1763
#: ../../library/argparse.rst:902
1732
1764
msgid "default"
1733
- msgstr ""
1765
+ msgstr "default "
1734
1766
1735
1767
#: ../../library/argparse.rst:904
1736
1768
msgid ""
@@ -1741,6 +1773,9 @@ msgid ""
1741
1773
"the ``default`` value is used when the option string was not present at the "
1742
1774
"command line::"
1743
1775
msgstr ""
1776
+ "所有可選引數和部份位置引數可以在命令中省略。 :meth:`~ArgumentParser."
1777
+ "add_argument` 的關鍵字引數 ``default`` 將指定該選項被省略時所使用的預設值,該值預設為 ``None``。"
1778
+ "對於可選選項而言,該選項的字串未出限於命令中時,``default`` 的值將被使用。"
1744
1779
1745
1780
#: ../../library/argparse.rst:911
1746
1781
msgid ""
@@ -1763,6 +1798,7 @@ msgid ""
1763
1798
"If the target namespace already has an attribute set, the action *default* "
1764
1799
"will not overwrite it::"
1765
1800
msgstr ""
1801
+ "如果目標的命名空間中已具有該屬性,*default* 將不會對其進行覆寫:::"
1766
1802
1767
1803
#: ../../library/argparse.rst:921
1768
1804
msgid ""
0 commit comments