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

Skip to content

Commit 30c0c3b

Browse files
committed
docs(library/argparse.po): up to line 1813
1 parent d4d5135 commit 30c0c3b

File tree

1 file changed

+39
-3
lines changed

1 file changed

+39
-3
lines changed

library/argparse.po

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1689,10 +1689,12 @@ msgid ""
16891689
"be produced. Actions that do not consume command-line arguments (e.g. "
16901690
"``'store_const'``) set ``nargs=0``."
16911691
msgstr ""
1692+
"如果未提供關鍵字參數 ``nargs``,將消耗的參數量將取決於 action_ 的選擇。一般來說這代表會消耗一個命令列參數,並產生一個物件(而非串列)。"
1693+
"不消耗命令列參數的動作將設定 ``nargs=0``。"
16921694

16931695
#: ../../library/argparse.rst:874
16941696
msgid "const"
1695-
msgstr ""
1697+
msgstr "const"
16961698

16971699
#: ../../library/argparse.rst:876
16981700
msgid ""
@@ -1701,6 +1703,7 @@ msgid ""
17011703
"required for the various :class:`ArgumentParser` actions. The two most "
17021704
"common uses of it are:"
17031705
msgstr ""
1706+
":meth:`~ArgumentParser.add_argument` 的 ``const`` 參數用來保存許多 :class:`ArgumentParser` 動作使用到、但不從命令列參數讀取的常數。最常用到的兩個情況有:::"
17041707

17051708
#: ../../library/argparse.rst:880
17061709
msgid ""
@@ -1711,7 +1714,31 @@ msgid ""
17111714
"``const`` is not provided to :meth:`~ArgumentParser.add_argument`, it will "
17121715
"receive a default value of ``None``."
17131716
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)
17151742
#: ../../library/argparse.rst:888
17161743
msgid ""
17171744
"When :meth:`~ArgumentParser.add_argument` is called with option strings "
@@ -1721,16 +1748,21 @@ msgid ""
17211748
"command-line argument following it, the value of ``const`` will be assumed "
17221749
"to be ``None`` instead. See the nargs_ description for examples."
17231750
msgstr ""
1751+
"當設定了選項字串(例如 ``-f`` 或 ``--foo``)給 :meth:`~ArgumentParser.add_argument` 且給予了 ``nargs='?'`` 時。"
1752+
"將建立一個能接收零或一個參數的可選選項。在剖析命令時,如果選項後方沒有對應的參數,``const`` 的值將作為預設值,若未設定則預設為 ``None``。"
1753+
"範例請見 nargs_ 的描述。"
17241754

17251755
#: ../../library/argparse.rst:895
17261756
msgid ""
17271757
"``const=None`` by default, including when ``action='append_const'`` or "
17281758
"``action='store_const'``."
17291759
msgstr ""
1760+
"預設 ``const=None``,包含 ``action='append_const'`` 或"
1761+
" ``action='store_const'`` 時。"
17301762

17311763
#: ../../library/argparse.rst:902
17321764
msgid "default"
1733-
msgstr ""
1765+
msgstr "default"
17341766

17351767
#: ../../library/argparse.rst:904
17361768
msgid ""
@@ -1741,6 +1773,9 @@ msgid ""
17411773
"the ``default`` value is used when the option string was not present at the "
17421774
"command line::"
17431775
msgstr ""
1776+
"所有可選引數和部份位置引數可以在命令中省略。 :meth:`~ArgumentParser."
1777+
"add_argument` 的關鍵字引數 ``default`` 將指定該選項被省略時所使用的預設值,該值預設為 ``None``。"
1778+
"對於可選選項而言,該選項的字串未出限於命令中時,``default`` 的值將被使用。"
17441779

17451780
#: ../../library/argparse.rst:911
17461781
msgid ""
@@ -1763,6 +1798,7 @@ msgid ""
17631798
"If the target namespace already has an attribute set, the action *default* "
17641799
"will not overwrite it::"
17651800
msgstr ""
1801+
"如果目標的命名空間中已具有該屬性,*default* 將不會對其進行覆寫:::"
17661802

17671803
#: ../../library/argparse.rst:921
17681804
msgid ""

0 commit comments

Comments
 (0)
0