-
-
Notifications
You must be signed in to change notification settings - Fork 102
Expand file tree
/
Copy pathargparse.po
More file actions
4144 lines (3757 loc) · 173 KB
/
Copy pathargparse.po
File metadata and controls
4144 lines (3757 loc) · 173 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# SOME DESCRIPTIVE TITLE.
# Copyright (C) 2001-2026, Python Software Foundation
# This file is distributed under the same license as the Python package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
# Translators:
# Freesand Leo <yuqinju@163.com>, 2026
# python-doc bot, 2026
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: Python 3.13\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2026-06-09 18:10+0000\n"
"PO-Revision-Date: 2025-09-15 01:03+0000\n"
"Last-Translator: python-doc bot, 2026\n"
"Language-Team: Chinese (China) (https://app.transifex.com/python-doc/teams/5390/zh_CN/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: zh_CN\n"
"Plural-Forms: nplurals=1; plural=0;\n"
#: ../../library/argparse.rst:2
msgid ""
":mod:`!argparse` --- Parser for command-line options, arguments and "
"subcommands"
msgstr ":mod:`!argparse` --- 用于命令行选项、参数和子命令的解析器"
#: ../../library/argparse.rst:12
msgid "**Source code:** :source:`Lib/argparse.py`"
msgstr "**源代码:** :source:`Lib/argparse.py`"
#: ../../library/argparse.rst:16
msgid ""
"While :mod:`argparse` is the default recommended standard library module for"
" implementing basic command line applications, authors with more exacting "
"requirements for exactly how their command line applications behave may find"
" it doesn't provide the necessary level of control. Refer to :ref:`choosing-"
"an-argument-parser` for alternatives to consider when ``argparse`` doesn't "
"support behaviors that the application requires (such as entirely disabling "
"support for interspersed options and positional arguments, or accepting "
"option parameter values that start with ``-`` even when they correspond to "
"another defined option)."
msgstr ""
"虽然 :mod:`argparse` "
"是推荐的用于实现基本命令行应用程序的标准库模块,但对于命令行应用程序的行为有更明确的要求的开发者可能会发现它并未提供所需层次的控制能力。 请参阅 "
":ref:`choosing-an-argument-parser` 了解当 ``argparse`` "
"不支持特定应用程序需要的行为(例如完全禁用散开选项和位置参数,或接受以 ``-`` 开头的选项形参值即使它们对应了其它已定义的选项)时可以考虑的替代。"
#: ../../library/argparse.rst-1
msgid "Tutorial"
msgstr "教程"
#: ../../library/argparse.rst:30
msgid ""
"This page contains the API reference information. For a more gentle "
"introduction to Python command-line parsing, have a look at the "
":ref:`argparse tutorial <argparse-tutorial>`."
msgstr ""
"此页面包含该 API 的参考信息。有关 Python 命令行解析更细致的介绍,请参阅 :ref:`argparse 教程 <argparse-"
"tutorial>`。"
#: ../../library/argparse.rst:34
msgid ""
"The :mod:`!argparse` module makes it easy to write user-friendly command-"
"line interfaces. The program defines what arguments it requires, and "
":mod:`!argparse` will figure out how to parse those out of :data:`sys.argv`."
" The :mod:`!argparse` module also automatically generates help and usage "
"messages. The module will also issue errors when users give the program "
"invalid arguments."
msgstr ""
":mod:`!argparse` 模块让编写用户友好的命令行接口变得容易。 程序定义它需要哪些参数,:mod:`!argparse` 将会知道如何从 "
":data:`sys.argv` 解析它们。 :mod:`!argparse` 模块还能自动生成帮助和用法消息文本。 "
"该模块还会在用户向程序传入无效参数时发出错误提示。"
#: ../../library/argparse.rst:40
msgid ""
"The :mod:`!argparse` module's support for command-line interfaces is built "
"around an instance of :class:`argparse.ArgumentParser`. It is a container "
"for argument specifications and has options that apply to the parser as "
"whole::"
msgstr ""
":mod:`!argparse` 模块对命令行界面的支持是围绕 :class:`argparse.ArgumentParser` 实例建立的。 "
"它是一个用于参数规格说明的容器并包含应用于解析器的一组选项::"
#: ../../library/argparse.rst:44
msgid ""
"parser = argparse.ArgumentParser(\n"
" prog='ProgramName',\n"
" description='What the program does',\n"
" epilog='Text at the bottom of help')"
msgstr ""
"parser = argparse.ArgumentParser(\n"
" prog='ProgramName',\n"
" description='What the program does',\n"
" epilog='Text at the bottom of help')"
#: ../../library/argparse.rst:49
msgid ""
"The :meth:`ArgumentParser.add_argument` method attaches individual argument "
"specifications to the parser. It supports positional arguments, options "
"that accept values, and on/off flags::"
msgstr ""
":meth:`ArgumentParser.add_argument` 方法将单个参数规格说明关联到解析器。 "
"它支持位置参数,接受各种值的选项,以及各种启用/禁用旗标::"
#: ../../library/argparse.rst:53
msgid ""
"parser.add_argument('filename') # positional argument\n"
"parser.add_argument('-c', '--count') # option that takes a value\n"
"parser.add_argument('-v', '--verbose',\n"
" action='store_true') # on/off flag"
msgstr ""
"parser.add_argument('filename') # 位置参数\n"
"parser.add_argument('-c', '--count') # 接受一个值的选项\n"
"parser.add_argument('-v', '--verbose',\n"
" action='store_true') # 启用/禁用旗标"
#: ../../library/argparse.rst:58
msgid ""
"The :meth:`ArgumentParser.parse_args` method runs the parser and places the "
"extracted data in a :class:`argparse.Namespace` object::"
msgstr ""
":meth:`ArgumentParser.parse_args` 方法运行解析器并将提取的数据放入 "
":class:`argparse.Namespace` 对象::"
#: ../../library/argparse.rst:61
msgid ""
"args = parser.parse_args()\n"
"print(args.filename, args.count, args.verbose)"
msgstr ""
"args = parser.parse_args()\n"
"print(args.filename, args.count, args.verbose)"
#: ../../library/argparse.rst:65
msgid ""
"If you're looking for a guide about how to upgrade :mod:`optparse` code to "
":mod:`!argparse`, see :ref:`Upgrading Optparse Code <upgrading-optparse-"
"code>`."
msgstr ""
"如果您正在寻找如何将 :mod:`optparse` 代码升级到 :mod:`!argparse` 的指南,请参阅 :ref:`Upgrading "
"Optparse Code <upgrading-optparse-code>`。"
#: ../../library/argparse.rst:69
msgid "ArgumentParser objects"
msgstr "ArgumentParser 对象"
#: ../../library/argparse.rst:78
msgid ""
"Create a new :class:`ArgumentParser` object. All parameters should be passed"
" as keyword arguments. Each parameter has its own more detailed description "
"below, but in short they are:"
msgstr ""
"创建一个新的 :class:`ArgumentParser` "
"对象。所有的参数都应当作为关键字参数传入。每个参数在下面都有它更详细的描述,但简而言之,它们是:"
#: ../../library/argparse.rst:82
msgid ""
"prog_ - The name of the program (default: ``os.path.basename(sys.argv[0])``)"
msgstr "prog_ - 程序的名称 (默认值: ``os.path.basename(sys.argv[0])``)"
#: ../../library/argparse.rst:85
msgid ""
"usage_ - The string describing the program usage (default: generated from "
"arguments added to parser)"
msgstr "usage_ - 描述程序用途的字符串(默认值:从添加到解析器的参数生成)"
#: ../../library/argparse.rst:88
msgid ""
"description_ - Text to display before the argument help (by default, no "
"text)"
msgstr "description_ - 要在参数帮助信息之前显示的文本(默认:无文本)"
#: ../../library/argparse.rst:91
msgid ""
"epilog_ - Text to display after the argument help (by default, no text)"
msgstr "epilog_ - 要在参数帮助信息之后显示的文本(默认:无文本)"
#: ../../library/argparse.rst:93
msgid ""
"parents_ - A list of :class:`ArgumentParser` objects whose arguments should "
"also be included"
msgstr "parents_ - 一个 :class:`ArgumentParser` 对象的列表,它们的参数也应包含在内"
#: ../../library/argparse.rst:96
msgid "formatter_class_ - A class for customizing the help output"
msgstr "formatter_class_ - 用于自定义帮助文档输出格式的类"
#: ../../library/argparse.rst:98
msgid ""
"prefix_chars_ - The set of characters that prefix optional arguments "
"(default: '-')"
msgstr "prefix_chars_ - 可选参数的前缀字符集合(默认值: '-')"
#: ../../library/argparse.rst:101
msgid ""
"fromfile_prefix_chars_ - The set of characters that prefix files from which "
"additional arguments should be read (default: ``None``)"
msgstr "fromfile_prefix_chars_ - 当需要从文件中读取其他参数时,用于标识文件名的前缀字符集合(默认值: ``None``)"
#: ../../library/argparse.rst:104
msgid ""
"argument_default_ - The global default value for arguments (default: "
"``None``)"
msgstr "argument_default_ - 参数的全局默认值(默认值: ``None``)"
#: ../../library/argparse.rst:107
msgid ""
"conflict_handler_ - The strategy for resolving conflicting optionals "
"(usually unnecessary)"
msgstr "conflict_handler_ - 解决冲突选项的策略(通常是不必要的)"
#: ../../library/argparse.rst:110
msgid ""
"add_help_ - Add a ``-h/--help`` option to the parser (default: ``True``)"
msgstr "add_help_ - 为解析器添加一个 ``-h/--help`` 选项(默认值: ``True``)"
#: ../../library/argparse.rst:112
msgid ""
"allow_abbrev_ - Allows long options to be abbreviated if the abbreviation is"
" unambiguous. (default: ``True``)"
msgstr "allow_abbrev_ - 如果缩写是无歧义的,则允许缩写长选项 (默认值:``True``)"
#: ../../library/argparse.rst:115
msgid ""
"exit_on_error_ - Determines whether or not :class:`!ArgumentParser` exits "
"with error info when an error occurs. (default: ``True``)"
msgstr ""
"exit_on_error_ - 确定当出现错误时,:class:`!ArgumentParser` "
"是否退出并显示错误信息。(默认值:``True``)"
#: ../../library/argparse.rst:118
msgid "*allow_abbrev* parameter was added."
msgstr "增加了 *allow_abbrev* 参数。"
#: ../../library/argparse.rst:121
msgid ""
"In previous versions, *allow_abbrev* also disabled grouping of short flags "
"such as ``-vv`` to mean ``-v -v``."
msgstr "在之前的版本中,*allow_abbrev* 还会禁用短旗标分组,例如 ``-vv`` 表示为 ``-v -v``。"
#: ../../library/argparse.rst:125
msgid "*exit_on_error* parameter was added."
msgstr "添加了 *exit_on_error* 形参。"
#: ../../library/argparse.rst:128 ../../library/argparse.rst:617
msgid "The following sections describe how each of these are used."
msgstr "以下部分描述这些参数如何使用。"
#: ../../library/argparse.rst:134
msgid "prog"
msgstr "prog"
#: ../../library/argparse.rst:137
msgid ""
"By default, :class:`ArgumentParser` calculates the name of the program to "
"display in help messages depending on the way the Python interpreter was "
"run:"
msgstr "默认情况下 ,:class:`ArgumentParser` 根据Python 解释器 的运行方式,计算出要在帮助信息中显示的程序名称:"
#: ../../library/argparse.rst:140
msgid ""
"The :func:`base name <os.path.basename>` of ``sys.argv[0]`` if a file was "
"passed as argument."
msgstr ""
"如果作为参数传递的是文件,则是``sys.argv[0]`` 的 :func:`base name <os.path.basename>` 。"
#: ../../library/argparse.rst:142
msgid ""
"The Python interpreter name followed by ``sys.argv[0]`` if a directory or a "
"zipfile was passed as argument."
msgstr "如果作为参数传递的是目录或 ZIP 文件,则是Python 解释器名称,后接 ``sys.argv[0]``。"
#: ../../library/argparse.rst:144
msgid ""
"The Python interpreter name followed by ``-m`` followed by the module or "
"package name if the :option:`-m` option was used."
msgstr "如果使用 :option:`-m` 选项则是在 Python 解释器名称后接 ``-m`` 再加模块或包的名称。"
#: ../../library/argparse.rst:147
msgid ""
"This default is almost always desirable because it will make the help "
"messages match the string that was used to invoke the program on the command"
" line. However, to change this default behavior, another value can be "
"supplied using the ``prog=`` argument to :class:`ArgumentParser`::"
msgstr ""
"默认行为几乎总是符合需求因为它将使帮助消息与在命令行上唤起程序所用的字符串相匹配。 不过,要更改此默认行为,可以将 ``prog=`` 参数传入 "
":class:`ArgumentParser` 以提供另外的值::"
#: ../../library/argparse.rst:152
msgid ""
">>> parser = argparse.ArgumentParser(prog='myprogram')\n"
">>> parser.print_help()\n"
"usage: myprogram [-h]\n"
"\n"
"options:\n"
" -h, --help show this help message and exit"
msgstr ""
">>> parser = argparse.ArgumentParser(prog='myprogram')\n"
">>> parser.print_help()\n"
"usage: myprogram [-h]\n"
"\n"
"options:\n"
" -h, --help show this help message and exit"
#: ../../library/argparse.rst:159
msgid ""
"Note that the program name, whether determined from ``sys.argv[0]`` or from "
"the ``prog=`` argument, is available to help messages using the ``%(prog)s``"
" format specifier."
msgstr ""
"需要注意的是,无论是从 ``sys.argv[0]`` 或是从 ``prog=`` 参数确定的程序名称,都可以在帮助消息里通过 ``%(prog)s``"
" 格式说明符来引用。"
#: ../../library/argparse.rst:165
msgid ""
">>> parser = argparse.ArgumentParser(prog='myprogram')\n"
">>> parser.add_argument('--foo', help='foo of the %(prog)s program')\n"
">>> parser.print_help()\n"
"usage: myprogram [-h] [--foo FOO]\n"
"\n"
"options:\n"
" -h, --help show this help message and exit\n"
" --foo FOO foo of the myprogram program"
msgstr ""
">>> parser = argparse.ArgumentParser(prog='myprogram')\n"
">>> parser.add_argument('--foo', help='foo of the %(prog)s program')\n"
">>> parser.print_help()\n"
"usage: myprogram [-h] [--foo FOO]\n"
"\n"
"options:\n"
" -h, --help show this help message and exit\n"
" --foo FOO foo of the myprogram program"
#: ../../library/argparse.rst:176
msgid "usage"
msgstr "usage(用法)"
#: ../../library/argparse.rst:178
msgid ""
"By default, :class:`ArgumentParser` calculates the usage message from the "
"arguments it contains. The default message can be overridden with the "
"``usage=`` keyword argument::"
msgstr ""
"默认情况下,:class:`ArgumentParser` 会从它所包含的参数中计算出用法消息。 默认消息可以通过 ``usage=`` "
"关键字参数进行覆盖。"
#: ../../library/argparse.rst:182
msgid ""
">>> parser = argparse.ArgumentParser(prog='PROG', usage='%(prog)s [options]')\n"
">>> parser.add_argument('--foo', nargs='?', help='foo help')\n"
">>> parser.add_argument('bar', nargs='+', help='bar help')\n"
">>> parser.print_help()\n"
"usage: PROG [options]\n"
"\n"
"positional arguments:\n"
" bar bar help\n"
"\n"
"options:\n"
" -h, --help show this help message and exit\n"
" --foo [FOO] foo help"
msgstr ""
">>> parser = argparse.ArgumentParser(prog='PROG', usage='%(prog)s [options]')\n"
">>> parser.add_argument('--foo', nargs='?', help='foo help')\n"
">>> parser.add_argument('bar', nargs='+', help='bar help')\n"
">>> parser.print_help()\n"
"usage: PROG [options]\n"
"\n"
"positional arguments:\n"
" bar bar help\n"
"\n"
"options:\n"
" -h, --help show this help message and exit\n"
" --foo [FOO] foo help"
#: ../../library/argparse.rst:195
msgid ""
"The ``%(prog)s`` format specifier is available to fill in the program name "
"in your usage messages."
msgstr "在用法消息中可以使用 ``%(prog)s`` 格式说明符来填入程序名称。"
#: ../../library/argparse.rst:202
msgid "description"
msgstr "description(描述)"
#: ../../library/argparse.rst:204
msgid ""
"Most calls to the :class:`ArgumentParser` constructor will use the "
"``description=`` keyword argument. This argument gives a brief description "
"of what the program does and how it works. In help messages, the "
"description is displayed between the command-line usage string and the help "
"messages for the various arguments."
msgstr ""
"大多数对 :class:`ArgumentParser` 构造器的调用都会使用 ``description=`` 关键字参数。 "
"这个参数简要描述这个程序做什么以及怎么做。 在帮助消息中,这个描述会显示在命令行用法字符串和各种参数的帮助消息之间。"
#: ../../library/argparse.rst:210
msgid ""
"By default, the description will be line-wrapped so that it fits within the "
"given space. To change this behavior, see the formatter_class_ argument."
msgstr "在默认情况下,description 将被换行以便适应给定的空间。如果想改变这种行为,见 formatter_class_ 参数。"
#: ../../library/argparse.rst:215
msgid "epilog"
msgstr "epilog"
#: ../../library/argparse.rst:217
msgid ""
"Some programs like to display additional description of the program after "
"the description of the arguments. Such text can be specified using the "
"``epilog=`` argument to :class:`ArgumentParser`::"
msgstr ""
"一些程序喜欢在 description 参数后显示额外的对程序的描述。这种文字能够通过给 :class:`ArgumentParser`:: 提供 "
"``epilog=`` 参数而被指定。"
#: ../../library/argparse.rst:221
msgid ""
">>> parser = argparse.ArgumentParser(\n"
"... description='A foo that bars',\n"
"... epilog=\"And that's how you'd foo a bar\")\n"
">>> parser.print_help()\n"
"usage: argparse.py [-h]\n"
"\n"
"A foo that bars\n"
"\n"
"options:\n"
" -h, --help show this help message and exit\n"
"\n"
"And that's how you'd foo a bar"
msgstr ""
">>> parser = argparse.ArgumentParser(\n"
"... description='A foo that bars',\n"
"... epilog=\"And that's how you'd foo a bar\")\n"
">>> parser.print_help()\n"
"usage: argparse.py [-h]\n"
"\n"
"A foo that bars\n"
"\n"
"options:\n"
" -h, --help show this help message and exit\n"
"\n"
"And that's how you'd foo a bar"
#: ../../library/argparse.rst:234
msgid ""
"As with the description_ argument, the ``epilog=`` text is by default line-"
"wrapped, but this behavior can be adjusted with the formatter_class_ "
"argument to :class:`ArgumentParser`."
msgstr ""
"和 description_ 参数一样,``epilog=`` text 在默认情况下会换行,但是这种行为能够被调整通过提供 "
"formatter_class_ 参数给 :class:`ArgumentParse`."
#: ../../library/argparse.rst:240
msgid "parents"
msgstr "parents"
#: ../../library/argparse.rst:242
msgid ""
"Sometimes, several parsers share a common set of arguments. Rather than "
"repeating the definitions of these arguments, a single parser with all the "
"shared arguments and passed to ``parents=`` argument to "
":class:`ArgumentParser` can be used. The ``parents=`` argument takes a list"
" of :class:`ArgumentParser` objects, collects all the positional and "
"optional actions from them, and adds these actions to the "
":class:`ArgumentParser` object being constructed::"
msgstr ""
"有些时候,少数解析器会使用同一系列参数。 单个解析器能够通过提供 ``parents=`` 参数给 :class:`ArgumentParser` "
"而使用相同的参数而不是重复这些参数的定义。``parents=`` 参数使用 :class:`ArgumentParser` "
"对象的列表,从它们那里收集所有的位置和可选的行为,然后将这写行为加到正在构建的 :class:`ArgumentParser` 对象。"
#: ../../library/argparse.rst:249
msgid ""
">>> parent_parser = argparse.ArgumentParser(add_help=False)\n"
">>> parent_parser.add_argument('--parent', type=int)\n"
"\n"
">>> foo_parser = argparse.ArgumentParser(parents=[parent_parser])\n"
">>> foo_parser.add_argument('foo')\n"
">>> foo_parser.parse_args(['--parent', '2', 'XXX'])\n"
"Namespace(foo='XXX', parent=2)\n"
"\n"
">>> bar_parser = argparse.ArgumentParser(parents=[parent_parser])\n"
">>> bar_parser.add_argument('--bar')\n"
">>> bar_parser.parse_args(['--bar', 'YYY'])\n"
"Namespace(bar='YYY', parent=None)"
msgstr ""
">>> parent_parser = argparse.ArgumentParser(add_help=False)\n"
">>> parent_parser.add_argument('--parent', type=int)\n"
"\n"
">>> foo_parser = argparse.ArgumentParser(parents=[parent_parser])\n"
">>> foo_parser.add_argument('foo')\n"
">>> foo_parser.parse_args(['--parent', '2', 'XXX'])\n"
"Namespace(foo='XXX', parent=2)\n"
"\n"
">>> bar_parser = argparse.ArgumentParser(parents=[parent_parser])\n"
">>> bar_parser.add_argument('--bar')\n"
">>> bar_parser.parse_args(['--bar', 'YYY'])\n"
"Namespace(bar='YYY', parent=None)"
#: ../../library/argparse.rst:262
msgid ""
"Note that most parent parsers will specify ``add_help=False``. Otherwise, "
"the :class:`ArgumentParser` will see two ``-h/--help`` options (one in the "
"parent and one in the child) and raise an error."
msgstr ""
"请注意大多数父解析器会指定 ``add_help=False`` . 否则, :class:`ArgumentParse` 将会看到两个 "
"``-h/--help`` 选项(一个在父参数中一个在子参数中)并且产生一个错误。"
#: ../../library/argparse.rst:267
msgid ""
"You must fully initialize the parsers before passing them via ``parents=``. "
"If you change the parent parsers after the child parser, those changes will "
"not be reflected in the child."
msgstr "你在通过 ``parents=`` 传递解析器之前必须完全初始化它们。 如果你在子解析器之后改变父解析器,这些改变将不会反映在子解析器上。"
#: ../../library/argparse.rst:275
msgid "formatter_class"
msgstr "formatter_class"
#: ../../library/argparse.rst:277
msgid ""
":class:`ArgumentParser` objects allow the help formatting to be customized "
"by specifying an alternate formatting class. Currently, there are four such"
" classes:"
msgstr ":class:`ArgumentParser` 对象允许通过指定备用格式化类来自定义帮助格式。目前,有四种这样的类。"
#: ../../library/argparse.rst:286
msgid ""
":class:`RawDescriptionHelpFormatter` and :class:`RawTextHelpFormatter` give "
"more control over how textual descriptions are displayed. By default, "
":class:`ArgumentParser` objects line-wrap the description_ and epilog_ texts"
" in command-line help messages::"
msgstr ""
":class:`RawDescriptionHelpFormatter` 和 :class:`RawTextHelpFormatter` "
"在正文的描述和展示上给与了更多的控制。:class:`ArgumentParser` 对象会将 description_ 和 epilog_ "
"的文字在命令行中自动换行。"
#: ../../library/argparse.rst:291
msgid ""
">>> parser = argparse.ArgumentParser(\n"
"... prog='PROG',\n"
"... description='''this description\n"
"... was indented weird\n"
"... but that is okay''',\n"
"... epilog='''\n"
"... likewise for this epilog whose whitespace will\n"
"... be cleaned up and whose words will be wrapped\n"
"... across a couple lines''')\n"
">>> parser.print_help()\n"
"usage: PROG [-h]\n"
"\n"
"this description was indented weird but that is okay\n"
"\n"
"options:\n"
" -h, --help show this help message and exit\n"
"\n"
"likewise for this epilog whose whitespace will be cleaned up and whose words\n"
"will be wrapped across a couple lines"
msgstr ""
">>> parser = argparse.ArgumentParser(\n"
"... prog='PROG',\n"
"... description='''this description\n"
"... was indented weird\n"
"... but that is okay''',\n"
"... epilog='''\n"
"... likewise for this epilog whose whitespace will\n"
"... be cleaned up and whose words will be wrapped\n"
"... across a couple lines''')\n"
">>> parser.print_help()\n"
"usage: PROG [-h]\n"
"\n"
"this description was indented weird but that is okay\n"
"\n"
"options:\n"
" -h, --help show this help message and exit\n"
"\n"
"likewise for this epilog whose whitespace will be cleaned up and whose words\n"
"will be wrapped across a couple lines"
#: ../../library/argparse.rst:311
msgid ""
"Passing :class:`RawDescriptionHelpFormatter` as ``formatter_class=`` "
"indicates that description_ and epilog_ are already correctly formatted and "
"should not be line-wrapped::"
msgstr ""
"传 :class:`RawDescriptionHelpFormatter` 给 ``formatter_class=`` 表示 "
"description_ 和 epilog_ 已经被正确的格式化了,不能在命令行中被自动换行::"
#: ../../library/argparse.rst:315
msgid ""
">>> parser = argparse.ArgumentParser(\n"
"... prog='PROG',\n"
"... formatter_class=argparse.RawDescriptionHelpFormatter,\n"
"... description=textwrap.dedent('''\\\n"
"... Please do not mess up this text!\n"
"... --------------------------------\n"
"... I have indented it\n"
"... exactly the way\n"
"... I want it\n"
"... '''))\n"
">>> parser.print_help()\n"
"usage: PROG [-h]\n"
"\n"
"Please do not mess up this text!\n"
"--------------------------------\n"
" I have indented it\n"
" exactly the way\n"
" I want it\n"
"\n"
"options:\n"
" -h, --help show this help message and exit"
msgstr ""
">>> parser = argparse.ArgumentParser(\n"
"... prog='PROG',\n"
"... formatter_class=argparse.RawDescriptionHelpFormatter,\n"
"... description=textwrap.dedent('''\\\n"
"... Please do not mess up this text!\n"
"... --------------------------------\n"
"... I have indented it\n"
"... exactly the way\n"
"... I want it\n"
"... '''))\n"
">>> parser.print_help()\n"
"usage: PROG [-h]\n"
"\n"
"Please do not mess up this text!\n"
"--------------------------------\n"
" I have indented it\n"
" exactly the way\n"
" I want it\n"
"\n"
"options:\n"
" -h, --help show this help message and exit"
#: ../../library/argparse.rst:337
msgid ""
":class:`RawTextHelpFormatter` maintains whitespace for all sorts of help "
"text, including argument descriptions. However, multiple newlines are "
"replaced with one. If you wish to preserve multiple blank lines, add spaces "
"between the newlines."
msgstr ""
":class:`RawTextHelpFormatter` 保留各种帮助文本的空白符,包括参数描述。 但是,多个换行符会被替换为一个。 "
"如果你希望保留多个空行,请在换行符之间添加空格。"
#: ../../library/argparse.rst:342
msgid ""
":class:`ArgumentDefaultsHelpFormatter` automatically adds information about "
"default values to each of the argument help messages::"
msgstr ":class:`ArgumentDefaultsHelpFormatter` 自动添加默认的值的信息到每一个帮助信息的参数中::"
#: ../../library/argparse.rst:345
msgid ""
">>> parser = argparse.ArgumentParser(\n"
"... prog='PROG',\n"
"... formatter_class=argparse.ArgumentDefaultsHelpFormatter)\n"
">>> parser.add_argument('--foo', type=int, default=42, help='FOO!')\n"
">>> parser.add_argument('bar', nargs='*', default=[1, 2, 3], help='BAR!')\n"
">>> parser.print_help()\n"
"usage: PROG [-h] [--foo FOO] [bar ...]\n"
"\n"
"positional arguments:\n"
" bar BAR! (default: [1, 2, 3])\n"
"\n"
"options:\n"
" -h, --help show this help message and exit\n"
" --foo FOO FOO! (default: 42)"
msgstr ""
">>> parser = argparse.ArgumentParser(\n"
"... prog='PROG',\n"
"... formatter_class=argparse.ArgumentDefaultsHelpFormatter)\n"
">>> parser.add_argument('--foo', type=int, default=42, help='FOO!')\n"
">>> parser.add_argument('bar', nargs='*', default=[1, 2, 3], help='BAR!')\n"
">>> parser.print_help()\n"
"usage: PROG [-h] [--foo FOO] [bar ...]\n"
"\n"
"positional arguments:\n"
" bar BAR! (default: [1, 2, 3])\n"
"\n"
"options:\n"
" -h, --help show this help message and exit\n"
" --foo FOO FOO! (default: 42)"
#: ../../library/argparse.rst:360
msgid ""
":class:`MetavarTypeHelpFormatter` uses the name of the type_ argument for "
"each argument as the display name for its values (rather than using the "
"dest_ as the regular formatter does)::"
msgstr ""
":class:`MetavarTypeHelpFormatter` 为它的值在每一个参数中使用 type_ 的参数名当作它的显示名(而不是使用通常的格式"
" dest_ )::"
#: ../../library/argparse.rst:364
msgid ""
">>> parser = argparse.ArgumentParser(\n"
"... prog='PROG',\n"
"... formatter_class=argparse.MetavarTypeHelpFormatter)\n"
">>> parser.add_argument('--foo', type=int)\n"
">>> parser.add_argument('bar', type=float)\n"
">>> parser.print_help()\n"
"usage: PROG [-h] [--foo int] float\n"
"\n"
"positional arguments:\n"
" float\n"
"\n"
"options:\n"
" -h, --help show this help message and exit\n"
" --foo int"
msgstr ""
">>> parser = argparse.ArgumentParser(\n"
"... prog='PROG',\n"
"... formatter_class=argparse.MetavarTypeHelpFormatter)\n"
">>> parser.add_argument('--foo', type=int)\n"
">>> parser.add_argument('bar', type=float)\n"
">>> parser.print_help()\n"
"usage: PROG [-h] [--foo int] float\n"
"\n"
"positional arguments:\n"
" float\n"
"\n"
"options:\n"
" -h, --help show this help message and exit\n"
" --foo int"
#: ../../library/argparse.rst:381
msgid "prefix_chars"
msgstr "prefix_chars"
#: ../../library/argparse.rst:383
msgid ""
"Most command-line options will use ``-`` as the prefix, e.g. ``-f/--foo``. "
"Parsers that need to support different or additional prefix characters, e.g."
" for options like ``+f`` or ``/foo``, may specify them using the "
"``prefix_chars=`` argument to the :class:`ArgumentParser` constructor::"
msgstr ""
"大多数命令行选项会使用 ``-`` 作为前缀,例如 ``-f/--foo``。 如果解析器需要支持不同的或者额外的前缀字符,例如像 ``+f`` 或 "
"``/foo`` 之类的选项,可以在 :class:`ArgumentParser` 构造器中使用 ``prefix_chars=`` "
"参数来指定它们::"
#: ../../library/argparse.rst:389
msgid ""
">>> parser = argparse.ArgumentParser(prog='PROG', prefix_chars='-+')\n"
">>> parser.add_argument('+f')\n"
">>> parser.add_argument('++bar')\n"
">>> parser.parse_args('+f X ++bar Y'.split())\n"
"Namespace(bar='Y', f='X')"
msgstr ""
">>> parser = argparse.ArgumentParser(prog='PROG', prefix_chars='-+')\n"
">>> parser.add_argument('+f')\n"
">>> parser.add_argument('++bar')\n"
">>> parser.parse_args('+f X ++bar Y'.split())\n"
"Namespace(bar='Y', f='X')"
#: ../../library/argparse.rst:395
msgid ""
"The ``prefix_chars=`` argument defaults to ``'-'``. Supplying a set of "
"characters that does not include ``-`` will cause ``-f/--foo`` options to be"
" disallowed."
msgstr ""
"``prefix_chars=`` 参数默认使用 ``'-'``。 提供一组不包括 ``-`` 的字符将导致 ``-f/--foo`` 选项不被允许。"
#: ../../library/argparse.rst:401
msgid "fromfile_prefix_chars"
msgstr "fromfile_prefix_chars"
#: ../../library/argparse.rst:403
msgid ""
"Sometimes, when dealing with a particularly long argument list, it may make "
"sense to keep the list of arguments in a file rather than typing it out at "
"the command line. If the ``fromfile_prefix_chars=`` argument is given to "
"the :class:`ArgumentParser` constructor, then arguments that start with any "
"of the specified characters will be treated as files, and will be replaced "
"by the arguments they contain. For example::"
msgstr ""
"在某些时候,如在处理一个特别长的参数列表时,把参数列表保存在一个文件中而不是在命令行中打印出来会更有意义。 如果提供 "
"``fromfile_prefix_chars=`` 参数给 :class:`ArgumentParser` "
"构造器,则任何以指定字符打头的参数都将被当作文件来处理,并将被它们包含的参数所替代。 举例来说::"
#: ../../library/argparse.rst:410
msgid ""
">>> with open('args.txt', 'w', encoding=sys.getfilesystemencoding()) as fp:\n"
"... fp.write('-f\\nbar')\n"
"...\n"
">>> parser = argparse.ArgumentParser(fromfile_prefix_chars='@')\n"
">>> parser.add_argument('-f')\n"
">>> parser.parse_args(['-f', 'foo', '@args.txt'])\n"
"Namespace(f='bar')"
msgstr ""
">>> with open('args.txt', 'w', encoding=sys.getfilesystemencoding()) as fp:\n"
"... fp.write('-f\\nbar')\n"
"...\n"
">>> parser = argparse.ArgumentParser(fromfile_prefix_chars='@')\n"
">>> parser.add_argument('-f')\n"
">>> parser.parse_args(['-f', 'foo', '@args.txt'])\n"
"Namespace(f='bar')"
#: ../../library/argparse.rst:418
msgid ""
"Arguments read from a file must be one per line by default (but see also "
":meth:`~ArgumentParser.convert_arg_line_to_args`) and are treated as if they"
" were in the same place as the original file referencing argument on the "
"command line. So in the example above, the expression ``['-f', 'foo', "
"'@args.txt']`` is considered equivalent to the expression ``['-f', 'foo', "
"'-f', 'bar']``."
msgstr ""
"从文件读取的参数在默认情况下必须一个一行(但是可参见 "
":meth:`~ArgumentParser.convert_arg_line_to_args`)并且它们被视为与命令行上的原始文件引用参数位于同一位置。所以在以上例子中,``['-f',"
" 'foo', '@args.txt']`` 的表达式和 ``['-f', 'foo', '-f', 'bar']`` 的表达式相同。"
#: ../../library/argparse.rst:426
msgid ""
"Each line is treated as a single argument, so an empty line is read as an "
"empty string (``''``)."
msgstr ""
#: ../../library/argparse.rst:429
msgid ""
":class:`ArgumentParser` uses :term:`filesystem encoding and error handler` "
"to read the file containing arguments."
msgstr ""
":class:`ArgumentParser` 使用 :term:`filesystem encoding and error handler` "
"来读取包含参数的文件。"
#: ../../library/argparse.rst:432
msgid ""
"The ``fromfile_prefix_chars=`` argument defaults to ``None``, meaning that "
"arguments will never be treated as file references."
msgstr "``fromfile_prefix_chars=`` 参数默认为 ``None``,意味着参数不会被当作文件对待。"
#: ../../library/argparse.rst:435
msgid ""
":class:`ArgumentParser` changed encoding and errors to read arguments files "
"from default (e.g. :func:`locale.getpreferredencoding(False) "
"<locale.getpreferredencoding>` and ``\"strict\"``) to the :term:`filesystem "
"encoding and error handler`. Arguments file should be encoded in UTF-8 "
"instead of ANSI Codepage on Windows."
msgstr ""
":class:`ArgumentParser` 将读取参数的编码格式和错误处理方式从默认值 (即 "
":func:`locale.getpreferredencoding(False) <locale.getpreferredencoding>` 和 "
"``\"strict\"``) 改为 :term:`filesystem encoding and error handler`。 在 Windows "
"上参数文件应当以 UTF-8 而不是 ANSI 代码页来编码。"
#: ../../library/argparse.rst:443
msgid "argument_default"
msgstr "argument_default"
#: ../../library/argparse.rst:445
msgid ""
"Generally, argument defaults are specified either by passing a default to "
":meth:`~ArgumentParser.add_argument` or by calling the "
":meth:`~ArgumentParser.set_defaults` methods with a specific set of name-"
"value pairs. Sometimes however, it may be useful to specify a single "
"parser-wide default for arguments. This can be accomplished by passing the "
"``argument_default=`` keyword argument to :class:`ArgumentParser`. For "
"example, to globally suppress attribute creation on "
":meth:`~ArgumentParser.parse_args` calls, we supply "
"``argument_default=SUPPRESS``::"
msgstr ""
"一般情况下,参数默认会通过设置一个默认到 :meth:`~ArgumentParser.add_argument` 或者调用带一组指定键值对的 "
":meth:`ArgumentParser.set_defaults` 方法。但是有些时候,为参数指定一个普遍适用的解析器会更有用。这能够通过传输 "
"``argument_default=`` 关键词参数给 :class:`ArgumentParser` 来完成。举个栗子,要全局禁止在 "
":meth:`~ArgumentParser.parse_args` 中创建属性,我们提供 "
"``argument_default=SUPPRESS``::"
#: ../../library/argparse.rst:454
msgid ""
">>> parser = argparse.ArgumentParser(argument_default=argparse.SUPPRESS)\n"
">>> parser.add_argument('--foo')\n"
">>> parser.add_argument('bar', nargs='?')\n"
">>> parser.parse_args(['--foo', '1', 'BAR'])\n"
"Namespace(bar='BAR', foo='1')\n"
">>> parser.parse_args([])\n"
"Namespace()"
msgstr ""
">>> parser = argparse.ArgumentParser(argument_default=argparse.SUPPRESS)\n"
">>> parser.add_argument('--foo')\n"
">>> parser.add_argument('bar', nargs='?')\n"
">>> parser.parse_args(['--foo', '1', 'BAR'])\n"
"Namespace(bar='BAR', foo='1')\n"
">>> parser.parse_args([])\n"
"Namespace()"
#: ../../library/argparse.rst:465
msgid "allow_abbrev"
msgstr "allow_abbrev"
#: ../../library/argparse.rst:467
msgid ""
"Normally, when you pass an argument list to the "
":meth:`~ArgumentParser.parse_args` method of an :class:`ArgumentParser`, it "
":ref:`recognizes abbreviations <prefix-matching>` of long options."
msgstr ""
"正常情况下,当你向 :class:`ArgumentParser` 的 :meth:`~ArgumentParser.parse_args` "
"方法传入一个参数列表时,它会 :ref:`recognizes abbreviations <prefix-matching>`。"
#: ../../library/argparse.rst:471
msgid ""
"This feature can be disabled by setting ``allow_abbrev`` to ``False``::"
msgstr "这个特性可以设置 ``allow_abbrev`` 为 ``False`` 来关闭::"
#: ../../library/argparse.rst:473
msgid ""
">>> parser = argparse.ArgumentParser(prog='PROG', allow_abbrev=False)\n"
">>> parser.add_argument('--foobar', action='store_true')\n"
">>> parser.add_argument('--foonley', action='store_false')\n"
">>> parser.parse_args(['--foon'])\n"
"usage: PROG [-h] [--foobar] [--foonley]\n"
"PROG: error: unrecognized arguments: --foon"
msgstr ""
">>> parser = argparse.ArgumentParser(prog='PROG', allow_abbrev=False)\n"
">>> parser.add_argument('--foobar', action='store_true')\n"
">>> parser.add_argument('--foonley', action='store_false')\n"
">>> parser.parse_args(['--foon'])\n"
"usage: PROG [-h] [--foobar] [--foonley]\n"
"PROG: error: unrecognized arguments: --foon"
#: ../../library/argparse.rst:484
msgid "conflict_handler"
msgstr "conflict_handler"
#: ../../library/argparse.rst:486
msgid ""
":class:`ArgumentParser` objects do not allow two actions with the same "
"option string. By default, :class:`ArgumentParser` objects raise an "
"exception if an attempt is made to create an argument with an option string "
"that is already in use::"
msgstr ""
":class:`ArgumentParser` 对象不允许在相同选项字符串下有两种行为。默认情况下, :class:`ArgumentParser` "
"对象会产生一个异常如果去创建一个正在使用的选项字符串参数。"
#: ../../library/argparse.rst:491
msgid ""
">>> parser = argparse.ArgumentParser(prog='PROG')\n"
">>> parser.add_argument('-f', '--foo', help='old foo help')\n"
">>> parser.add_argument('--foo', help='new foo help')\n"
"Traceback (most recent call last):\n"
" ..\n"
"ArgumentError: argument --foo: conflicting option string(s): --foo"
msgstr ""
">>> parser = argparse.ArgumentParser(prog='PROG')\n"
">>> parser.add_argument('-f', '--foo', help='old foo help')\n"
">>> parser.add_argument('--foo', help='new foo help')\n"
"Traceback (most recent call last):\n"
" ..\n"
"ArgumentError: argument --foo: conflicting option string(s): --foo"
#: ../../library/argparse.rst:498
msgid ""
"Sometimes (e.g. when using parents_) it may be useful to simply override any"
" older arguments with the same option string. To get this behavior, the "
"value ``'resolve'`` can be supplied to the ``conflict_handler=`` argument of"
" :class:`ArgumentParser`::"
msgstr ""
"有些时候(例如:使用 parents_),重写旧的有相同选项字符串的参数会更有用。为了产生这种行为, ``'resolve'`` 值可以提供给 "
":class:`ArgumentParser` 的 ``conflict_handler=`` 参数::"
#: ../../library/argparse.rst:503
msgid ""
">>> parser = argparse.ArgumentParser(prog='PROG', conflict_handler='resolve')\n"
">>> parser.add_argument('-f', '--foo', help='old foo help')\n"
">>> parser.add_argument('--foo', help='new foo help')\n"
">>> parser.print_help()\n"
"usage: PROG [-h] [-f FOO] [--foo FOO]\n"
"\n"
"options:\n"
" -h, --help show this help message and exit\n"
" -f FOO old foo help\n"
" --foo FOO new foo help"
msgstr ""
">>> parser = argparse.ArgumentParser(prog='PROG', conflict_handler='resolve')\n"
">>> parser.add_argument('-f', '--foo', help='old foo help')\n"
">>> parser.add_argument('--foo', help='new foo help')\n"
">>> parser.print_help()\n"
"usage: PROG [-h] [-f FOO] [--foo FOO]\n"
"\n"
"options:\n"
" -h, --help show this help message and exit\n"
" -f FOO old foo help\n"
" --foo FOO new foo help"
#: ../../library/argparse.rst:514
msgid ""
"Note that :class:`ArgumentParser` objects only remove an action if all of "
"its option strings are overridden. So, in the example above, the old "
"``-f/--foo`` action is retained as the ``-f`` action, because only the "
"``--foo`` option string was overridden."
msgstr ""
"注意 :class:`ArgumentParser` 对象只能移除一个行为如果它所有的选项字符串都被重写。所以,在上面的例子中,旧的 "
"``-f/--foo`` 行为 回合 ``-f`` 行为保持一样, 因为只有 ``--foo`` 选项字符串被重写。"
#: ../../library/argparse.rst:521
msgid "add_help"
msgstr "add_help"
#: ../../library/argparse.rst:523
msgid ""
"By default, :class:`ArgumentParser` objects add an option which simply "
"displays the parser's help message. If ``-h`` or ``--help`` is supplied at "
"the command line, the :class:`!ArgumentParser` help will be printed."
msgstr ""