@@ -12,7 +12,7 @@ msgid ""
12
12
msgstr ""
13
13
"Project-Id-Version : Python 3.13\n "
14
14
"Report-Msgid-Bugs-To : \n "
15
- "POT-Creation-Date : 2024-09-24 07:20 +0000\n "
15
+ "POT-Creation-Date : 2024-10-18 00:14 +0000\n "
16
16
"PO-Revision-Date : 2023-12-11 17:33+0800\n "
17
17
"
Last-Translator :
Matt Wang <[email protected] >\n "
18
18
"Language-Team : Chinese - TAIWAN (https://github.com/python/python-docs-zh- "
@@ -1222,6 +1222,7 @@ msgstr ""
1222
1222
" print(answer)"
1223
1223
1224
1224
#: ../../howto/argparse.rst:618 ../../howto/argparse.rst:656
1225
+ #: ../../howto/argparse.rst:872
1225
1226
msgid "Output:"
1226
1227
msgstr "結果:"
1227
1228
@@ -1633,10 +1634,91 @@ msgid ""
1633
1634
msgstr "若要在 :mod:`argparse` 輸出中翻譯你自己的字串,請使用 :mod:`gettext`。"
1634
1635
1635
1636
#: ../../howto/argparse.rst:845
1637
+ msgid "Custom type converters"
1638
+ msgstr ""
1639
+
1640
+ #: ../../howto/argparse.rst:847
1641
+ msgid ""
1642
+ "The :mod:`argparse` module allows you to specify custom type converters for "
1643
+ "your command-line arguments. This allows you to modify user input before "
1644
+ "it's stored in the :class:`argparse.Namespace`. This can be useful when you "
1645
+ "need to pre-process the input before it is used in your program."
1646
+ msgstr ""
1647
+
1648
+ #: ../../howto/argparse.rst:852
1649
+ msgid ""
1650
+ "When using a custom type converter, you can use any callable that takes a "
1651
+ "single string argument (the argument value) and returns the converted value. "
1652
+ "However, if you need to handle more complex scenarios, you can use a custom "
1653
+ "action class with the **action** parameter instead."
1654
+ msgstr ""
1655
+
1656
+ #: ../../howto/argparse.rst:857
1657
+ msgid ""
1658
+ "For example, let's say you want to handle arguments with different prefixes "
1659
+ "and process them accordingly::"
1660
+ msgstr ""
1661
+
1662
+ #: ../../howto/argparse.rst:860
1663
+ #, fuzzy
1664
+ msgid ""
1665
+ "import argparse\n"
1666
+ "\n"
1667
+ "parser = argparse.ArgumentParser(prefix_chars='-+')\n"
1668
+ "\n"
1669
+ "parser.add_argument('-a', metavar='<value>', action='append',\n"
1670
+ " type=lambda x: ('-', x))\n"
1671
+ "parser.add_argument('+a', metavar='<value>', action='append',\n"
1672
+ " type=lambda x: ('+', x))\n"
1673
+ "\n"
1674
+ "args = parser.parse_args()\n"
1675
+ "print(args)"
1676
+ msgstr ""
1677
+ "import argparse\n"
1678
+ "parser = argparse.ArgumentParser()\n"
1679
+ "parser.add_argument(\" square\" , help=\" display a square of a given "
1680
+ "number\" ,\n"
1681
+ " type=int)\n"
1682
+ "args = parser.parse_args()\n"
1683
+ "print(args.square**2)"
1684
+
1685
+ #: ../../howto/argparse.rst:874
1686
+ msgid ""
1687
+ "$ python prog.py -a value1 +a value2\n"
1688
+ "Namespace(a=[('-', 'value1'), ('+', 'value2')])"
1689
+ msgstr ""
1690
+
1691
+ #: ../../howto/argparse.rst:879
1692
+ #, fuzzy
1693
+ msgid "In this example, we:"
1694
+ msgstr "例如: ::"
1695
+
1696
+ #: ../../howto/argparse.rst:881
1697
+ msgid ""
1698
+ "Created a parser with custom prefix characters using the ``prefix_chars`` "
1699
+ "parameter."
1700
+ msgstr ""
1701
+
1702
+ #: ../../howto/argparse.rst:884
1703
+ msgid ""
1704
+ "Defined two arguments, ``-a`` and ``+a``, which used the ``type`` parameter "
1705
+ "to create custom type converters to store the value in a tuple with the "
1706
+ "prefix."
1707
+ msgstr ""
1708
+
1709
+ #: ../../howto/argparse.rst:887
1710
+ msgid ""
1711
+ "Without the custom type converters, the arguments would have treated the ``-"
1712
+ "a`` and ``+a`` as the same argument, which would have been undesirable. By "
1713
+ "using custom type converters, we were able to differentiate between the two "
1714
+ "arguments."
1715
+ msgstr ""
1716
+
1717
+ #: ../../howto/argparse.rst:892
1636
1718
msgid "Conclusion"
1637
1719
msgstr "結論"
1638
1720
1639
- #: ../../howto/argparse.rst:847
1721
+ #: ../../howto/argparse.rst:894
1640
1722
msgid ""
1641
1723
"The :mod:`argparse` module offers a lot more than shown here. Its docs are "
1642
1724
"quite detailed and thorough, and full of examples. Having gone through this "
0 commit comments