@@ -2168,6 +2168,8 @@ msgid ""
2168
2168
"the only option attribute you must specify is ``callback``, the function to "
2169
2169
"call::"
2170
2170
msgstr ""
2171
+ "一般来说,定义回调选项的最简单方式是使用 :meth:`OptionParser.add_option` 方法。 在 "
2172
+ ":attr:`~Option.action` 之外,你必须指定的唯一选项属性是 ``callback``,即要调用的函数::"
2171
2173
2172
2174
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/library/optparse.rst:1571
2173
2175
msgid ""
@@ -2180,6 +2182,10 @@ msgid ""
2180
2182
"number of command-line arguments. This is where writing callbacks gets "
2181
2183
"tricky; it's covered later in this section."
2182
2184
msgstr ""
2185
+ "``callback`` 是一个函数(或其他可调用对象),因此当你创建这个回调选项时你必须已经定义了 ``my_callback()``。 "
2186
+ "在这个简单的例子中,:mod:`optparse` 甚至不知道 ``-c`` 是否接受任何参数,这通常意味着该选项不接受任何参数 --- "
2187
+ "它需要知道的就是存在命令行参数 ``-c``。 但是,在某些情况下,你可能希望你的回调接受任意数量的命令行参数。 "
2188
+ "这是编写回调的一个麻烦之处;本小节将稍后讲解这个问题。"
2183
2189
2184
2190
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/library/optparse.rst:1580
2185
2191
msgid ""
@@ -2188,16 +2194,18 @@ msgid ""
2188
2194
":attr:`~Option.callback_args` and :attr:`~Option.callback_kwargs`. Thus, "
2189
2195
"the minimal callback function signature is::"
2190
2196
msgstr ""
2197
+ ":mod:`optparse` 总是会向你的回调传递四个特定参数,它只会在你通过 :attr:`~Option.callback_args` 和 "
2198
+ ":attr:`~Option.callback_kwargs` 进行指定时才传入额外的参数。 因此,最小化的回调函数签名如下::"
2191
2199
2192
2200
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/library/optparse.rst:1587
2193
2201
msgid "The four arguments to a callback are described below."
2194
- msgstr ""
2202
+ msgstr "以下是对传给回调的四个参数的说明。 "
2195
2203
2196
2204
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/library/optparse.rst:1589
2197
2205
msgid ""
2198
2206
"There are several other option attributes that you can supply when you "
2199
2207
"define a callback option:"
2200
- msgstr ""
2208
+ msgstr "当你定义回调选项时还可以提供一些其他的选项属性: "
2201
2209
2202
2210
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/library/optparse.rst:1596
2203
2211
msgid ":attr:`~Option.type`"
@@ -2210,6 +2218,9 @@ msgid ""
2210
2218
":attr:`~Option.type`. Rather than storing the converted value(s) anywhere, "
2211
2219
"though, :mod:`optparse` passes it to your callback function."
2212
2220
msgstr ""
2221
+ "具有其通常的含义:与在 ``\" store\" `` 或 ``\" append\" `` 动作中一样,它指示 :mod:`optparse` "
2222
+ "读取一个参数并将其转换为 :attr:`~Option.type`。 但是,:mod:`optparse` "
2223
+ "并不会将所转换的值保存到某个地方,而是将其转给你的回调函数。"
2213
2224
2214
2225
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/library/optparse.rst:1602
2215
2226
msgid ":attr:`~Option.nargs`"
@@ -2222,38 +2233,40 @@ msgid ""
2222
2233
"to :attr:`~Option.type`. It then passes a tuple of converted values to your"
2223
2234
" callback."
2224
2235
msgstr ""
2236
+ "同样具有其通常的含义:如果提供了该属性并且其值 > 1,:mod:`optparse` 将读取 :attr:`~Option.nargs` "
2237
+ "个参数,每个参数都必须可被转换为 :attr:`~Option.type`。 随后它会将被转换值的元组传给你的回调。"
2225
2238
2226
2239
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/library/optparse.rst:1605
2227
2240
msgid ":attr:`~Option.callback_args`"
2228
2241
msgstr ":attr:`~Option.callback_args`"
2229
2242
2230
2243
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/library/optparse.rst:1605
2231
2244
msgid "a tuple of extra positional arguments to pass to the callback"
2232
- msgstr ""
2245
+ msgstr "一个要传给回调的由额外位置参数组成的元组 "
2233
2246
2234
2247
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/library/optparse.rst:1609
2235
2248
msgid ":attr:`~Option.callback_kwargs`"
2236
2249
msgstr ":attr:`~Option.callback_kwargs`"
2237
2250
2238
2251
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/library/optparse.rst:1608
2239
2252
msgid "a dictionary of extra keyword arguments to pass to the callback"
2240
- msgstr ""
2253
+ msgstr "一个要传给回调的由额外关键字参数组成的字典 "
2241
2254
2242
2255
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/library/optparse.rst:1614
2243
2256
msgid "How callbacks are called"
2244
- msgstr ""
2257
+ msgstr "回调应当如何调用 "
2245
2258
2246
2259
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/library/optparse.rst:1616
2247
2260
msgid "All callbacks are called as follows::"
2248
- msgstr ""
2261
+ msgstr "所有回调都将使用以下方式调用:: "
2249
2262
2250
2263
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/library/optparse.rst:1623
2251
2264
msgid "``option``"
2252
2265
msgstr "``option``"
2253
2266
2254
2267
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/library/optparse.rst:1623
2255
2268
msgid "is the Option instance that's calling the callback"
2256
- msgstr ""
2269
+ msgstr "是调用该回调的 Option 实例 "
2257
2270
2258
2271
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/library/optparse.rst:1630
2259
2272
msgid "``opt_str``"
@@ -2267,6 +2280,9 @@ msgid ""
2267
2280
"command-line as an abbreviation for ``--foobar``, then ``opt_str`` will be "
2268
2281
"``\" --foobar\" ``.)"
2269
2282
msgstr ""
2283
+ "是在触发回调的命令行参数中出现的选项字符串。 (如果使用了长选项的缩写形式,则 ``opt_str`` 将为完整规范的选项字符串 --- "
2284
+ "举例来说,如果用户在命令行中将 ``--foo`` 作为 ``--foobar`` 的缩写形式,则 ``opt_str`` 将为 ``\" --"
2285
+ "foobar\" ``。)"
2270
2286
2271
2287
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/library/optparse.rst:1637
2272
2288
msgid "``value``"
@@ -2281,6 +2297,10 @@ msgid ""
2281
2297
"then ``value`` will be ``None``. If :attr:`~Option.nargs` > 1, ``value`` "
2282
2298
"will be a tuple of values of the appropriate type."
2283
2299
msgstr ""
2300
+ "是在命令行中提供给该选项的参数。 :mod:`optparse` 将只在设置了 :attr:`~Option.type` "
2301
+ "的时候才接受参数;``value`` 将为该选项的类型所指定的类型。 如果该选项的 :attr:`~Option.type` 为 ``None`` "
2302
+ "(不接受参数),则 ``value`` 将为 ``None``。 如果 :attr:`~Option.nargs` > 1,则 ``value`` "
2303
+ "将为由指定类型的值组成的元组。"
2284
2304
2285
2305
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/library/optparse.rst:1660
2286
2306
msgid "``parser``"
@@ -2290,7 +2310,7 @@ msgstr "``parser``"
2290
2310
msgid ""
2291
2311
"is the OptionParser instance driving the whole thing, mainly useful because "
2292
2312
"you can access some other interesting data through its instance attributes:"
2293
- msgstr ""
2313
+ msgstr "是驱动选项解析过程的 OptionParser 实例,主要作用在于你可以通过其实例属性访问其他一些相关数据: "
2294
2314
2295
2315
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/library/optparse.rst:1647
2296
2316
msgid "``parser.largs``"
@@ -2303,6 +2323,8 @@ msgid ""
2303
2323
"``parser.largs``, e.g. by adding more arguments to it. (This list will "
2304
2324
"become ``args``, the second return value of :meth:`parse_args`.)"
2305
2325
msgstr ""
2326
+ "当前的剩余参数列表,即已被读取但不属于选项或选项参数的参数。 可以任意修改 ``parser.largs``,例如向其添加更多的参数。 (该列表将成为 "
2327
+ "``args``,即 :meth:`parse_args` 的第二个返回值。)"
2306
2328
2307
2329
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/library/optparse.rst:1653
2308
2330
msgid "``parser.rargs``"
@@ -2314,6 +2336,8 @@ msgid ""
2314
2336
"(if applicable) removed, and only the arguments following them still there."
2315
2337
" Feel free to modify ``parser.rargs``, e.g. by consuming more arguments."
2316
2338
msgstr ""
2339
+ "当前的保留参数列表,即移除了 ``opt_str`` 和 ``value`` (如果可用),并且只有在它们之后的参数才会被保留。 可以任意修改 "
2340
+ "``parser.rargs``,例如读取更多的参数。"
2317
2341
2318
2342
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/library/optparse.rst:1660
2319
2343
msgid "``parser.values``"
@@ -2327,12 +2351,14 @@ msgid ""
2327
2351
"around with globals or closures. You can also access or modify the value(s)"
2328
2352
" of any options already encountered on the command-line."
2329
2353
msgstr ""
2354
+ "作为选项值默认保存位置的对象(一个 optparse.OptionValues 实例)。 这使得回调能使用与 :mod:`optparse` "
2355
+ "的其他部分相同的机制来保存选项值;你不需要手动处理全局变量或闭包。 你还可以访问或修改在命令行中遇到的任何选项的值。"
2330
2356
2331
2357
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/library/optparse.rst:1663
2332
2358
msgid ""
2333
2359
"is a tuple of arbitrary positional arguments supplied via the "
2334
2360
":attr:`~Option.callback_args` option attribute."
2335
- msgstr ""
2361
+ msgstr "是一个由通过 :attr:`~Option.callback_args` 选项属性提供的任意位置参数组成的元组。 "
2336
2362
2337
2363
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/library/optparse.rst:1669
2338
2364
msgid "``kwargs``"
@@ -2342,11 +2368,11 @@ msgstr "``kwargs``"
2342
2368
msgid ""
2343
2369
"is a dictionary of arbitrary keyword arguments supplied via "
2344
2370
":attr:`~Option.callback_kwargs`."
2345
- msgstr ""
2371
+ msgstr "是一个由通过 :attr:`~Option.callback_kwargs` 提供的任意关键字参数组成的字典。 "
2346
2372
2347
2373
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/library/optparse.rst:1674
2348
2374
msgid "Raising errors in a callback"
2349
- msgstr ""
2375
+ msgstr "在回调中引发错误 "
2350
2376
2351
2377
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/library/optparse.rst:1676
2352
2378
msgid ""
@@ -2357,16 +2383,18 @@ msgid ""
2357
2383
" fault. Otherwise, the user will have a hard time figuring out what they did"
2358
2384
" wrong."
2359
2385
msgstr ""
2386
+ "如果选项或其参数存在任何问题则回调函数应当引发 :exc:`OptionValueError`。 :mod:`optparse` "
2387
+ "将捕获该异常并终止程序,将你提供的错误消息打印到 stderr。 你的消息应当清晰、简洁、准确并指明出错的选项。 否则,用户将很难弄清楚自己做错了什么。"
2360
2388
2361
2389
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/library/optparse.rst:1686
2362
2390
msgid "Callback example 1: trivial callback"
2363
- msgstr ""
2391
+ msgstr "回调示例 1:最简回调 "
2364
2392
2365
2393
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/library/optparse.rst:1688
2366
2394
msgid ""
2367
2395
"Here's an example of a callback option that takes no arguments, and simply "
2368
2396
"records that the option was seen::"
2369
- msgstr ""
2397
+ msgstr "下面是一个不接受任何参数,只是简单地记录所遇见的选项的回调选项示例:: "
2370
2398
2371
2399
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/library/optparse.rst:1696
2372
2400
msgid "Of course, you could do that with the ``\" store_true\" `` action."