-
-
Notifications
You must be signed in to change notification settings - Fork 91
Expand file tree
/
Copy pathcsv.po
More file actions
667 lines (579 loc) · 33.5 KB
/
csv.po
File metadata and controls
667 lines (579 loc) · 33.5 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
# SOME DESCRIPTIVE TITLE.
# Copyright (C) 2001-2025, Python Software Foundation
# This file is distributed under the same license as the Python package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
# Translators:
# python-doc bot, 2025
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: Python 3.9\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2025-09-22 21:56+0000\n"
"PO-Revision-Date: 2025-09-22 17:54+0000\n"
"Last-Translator: python-doc bot, 2025\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/csv.rst:2
msgid ":mod:`csv` --- CSV File Reading and Writing"
msgstr ":mod:`csv` --- CSV 文件读写"
#: ../../library/csv.rst:9
msgid "**Source code:** :source:`Lib/csv.py`"
msgstr "**源代码:** :source:`Lib/csv.py`"
#: ../../library/csv.rst:17
msgid ""
"The so-called CSV (Comma Separated Values) format is the most common import "
"and export format for spreadsheets and databases. CSV format was used for "
"many years prior to attempts to describe the format in a standardized way in"
" :rfc:`4180`. The lack of a well-defined standard means that subtle "
"differences often exist in the data produced and consumed by different "
"applications. These differences can make it annoying to process CSV files "
"from multiple sources. Still, while the delimiters and quoting characters "
"vary, the overall format is similar enough that it is possible to write a "
"single module which can efficiently manipulate such data, hiding the details"
" of reading and writing the data from the programmer."
msgstr ""
"CSV (Comma Separated Values) 格式是电子表格和数据库中最常见的输入、输出文件格式。在 :rfc:`4180` "
"规范推出的很多年前,CSV 格式就已经被开始使用了,由于当时并没有合理的标准,不同应用程序读写的数据会存在细微的差别。这种差别让处理多个来源的 CSV "
"文件变得困难。但尽管分隔符会变化,此类文件的大致格式是相似的,所以编写一个单独的模块以高效处理此类数据,将程序员从读写数据的繁琐细节中解放出来是有可能的。"
#: ../../library/csv.rst:28
msgid ""
"The :mod:`csv` module implements classes to read and write tabular data in "
"CSV format. It allows programmers to say, \"write this data in the format "
"preferred by Excel,\" or \"read data from this file which was generated by "
"Excel,\" without knowing the precise details of the CSV format used by "
"Excel. Programmers can also describe the CSV formats understood by other "
"applications or define their own special-purpose CSV formats."
msgstr ""
":mod:`csv` 模块实现了 CSV 格式表单数据的读写。其提供了诸如“以兼容 Excel 的方式输出数据文件”或“读取 Excel "
"程序输出的数据文件”的功能,程序员无需知道 Excel 所采用 CSV 格式的细节。此模块同样可以用于定义其他应用程序可用的 CSV "
"格式或定义特定需求的 CSV 格式。"
#: ../../library/csv.rst:35
msgid ""
"The :mod:`csv` module's :class:`reader` and :class:`writer` objects read and"
" write sequences. Programmers can also read and write data in dictionary "
"form using the :class:`DictReader` and :class:`DictWriter` classes."
msgstr ""
":mod:`csv` 模块中的 :class:`reader` 类和 :class:`writer` 类可用于读写序列化的数据。也可使用 "
":class:`DictReader` 类和 :class:`DictWriter` 类以字典的形式读写数据。"
#: ../../library/csv.rst:41
msgid ":pep:`305` - CSV File API"
msgstr "该实现在“Python 增强提议” - PEP `305` (CSV 文件 API) 中被提出"
#: ../../library/csv.rst:42
msgid ""
"The Python Enhancement Proposal which proposed this addition to Python."
msgstr "《Python 增强提议》提出了对 Python 的这一补充。"
#: ../../library/csv.rst:48
msgid "Module Contents"
msgstr "模块内容"
#: ../../library/csv.rst:50
msgid "The :mod:`csv` module defines the following functions:"
msgstr ":mod:`csv` 模块定义了以下函数:"
#: ../../library/csv.rst:58
msgid ""
"Return a reader object which will iterate over lines in the given *csvfile*."
" *csvfile* can be any object which supports the :term:`iterator` protocol "
"and returns a string each time its :meth:`!__next__` method is called --- "
":term:`file objects <file object>` and list objects are both suitable. If "
"*csvfile* is a file object, it should be opened with ``newline=''``. [1]_ "
"An optional *dialect* parameter can be given which is used to define a set "
"of parameters specific to a particular CSV dialect. It may be an instance "
"of a subclass of the :class:`Dialect` class or one of the strings returned "
"by the :func:`list_dialects` function. The other optional *fmtparams* "
"keyword arguments can be given to override individual formatting parameters "
"in the current dialect. For full details about the dialect and formatting "
"parameters, see section :ref:`csv-fmt-params`."
msgstr ""
"返回一个 reader 对象,该对象将逐行遍历 *csvfile*。*csvfile* 可以是任何对象,只要这个对象支持 "
":term:`iterator` 协议并在每次调用 :meth:`!__next__` 方法时都返回字符串,:term:`文件对象 <file "
"object>` 和列表对象均适用。如果 *csvfile* 是文件对象,则打开它时应使用 ``newline=''``。 [1]_ 可选参数 "
"*dialect* 是用于不同的 CSV 变种的特定参数组。它可以是 :class:`Dialect` 类的子类的实例,也可以是 "
":func:`list_dialects` 函数返回的字符串之一。另一个可选关键字参数 *fmtparams* "
"可以覆写当前变种格式中的单个格式设置。有关变种和格式设置参数的完整详细信息,请参见 :ref:`csv-fmt-params` 部分。"
#: ../../library/csv.rst:71
msgid ""
"Each row read from the csv file is returned as a list of strings. No "
"automatic data type conversion is performed unless the ``QUOTE_NONNUMERIC`` "
"format option is specified (in which case unquoted fields are transformed "
"into floats)."
msgstr ""
"csv 文件的每一行都读取为一个由字符串组成的列表。除非指定了 ``QUOTE_NONNUMERIC`` "
"格式选项(在这种情况下,未加引号的字段会转换为浮点数),否则不会执行自动数据类型转换。"
#: ../../library/csv.rst:75 ../../library/csv.rst:105
#: ../../library/csv.rst:176 ../../library/csv.rst:212
msgid "A short usage example::"
msgstr "一个简短的用法示例::"
#: ../../library/csv.rst:88
msgid ""
"Return a writer object responsible for converting the user's data into "
"delimited strings on the given file-like object. *csvfile* can be any "
"object with a :func:`write` method. If *csvfile* is a file object, it "
"should be opened with ``newline=''`` [1]_. An optional *dialect* parameter "
"can be given which is used to define a set of parameters specific to a "
"particular CSV dialect. It may be an instance of a subclass of the "
":class:`Dialect` class or one of the strings returned by the "
":func:`list_dialects` function. The other optional *fmtparams* keyword "
"arguments can be given to override individual formatting parameters in the "
"current dialect. For full details about dialects and formatting parameters,"
" see the :ref:`csv-fmt-params` section. To make it as easy as possible to "
"interface with modules which implement the DB API, the value :const:`None` "
"is written as the empty string. While this isn't a reversible "
"transformation, it makes it easier to dump SQL NULL data values to CSV files"
" without preprocessing the data returned from a ``cursor.fetch*`` call. All "
"other non-string data are stringified with :func:`str` before being written."
msgstr ""
"返回一个 writer 对象,该对象负责将用户的数据在给定的文件类对象上转换为带分隔符的字符串。 *csvfile* 可以是任何具有 "
":func:`write` 方法的对象。 如果 *csvfile* 是一个文件对象,则打开它时应使用 ``newline=''`` [1]_。 "
"可以给出可选的 *dialect* 形参用来定义一组特定 CSV 变种专属的形参。 它可以是 :class:`Dialect` 类的某个子类的实例或是 "
":func:`list_dialects` 函数所返回的字符串之一。 还可以给出另一个可选的 *fmtparams* "
"关键字参数来覆盖当前变种中的单个格式化形参。 有关各个变种和格式化形参的完整细节,请参阅 :ref:`csv-fmt-params` 部分。 "
"为了尽量简化与实现 DB API 的模块之间的接口,:const:`None` 值会被当作空字符串写入。 虽然这个转换是不可逆的,但它可以简化 SQL "
"NULL 数据值到 CSV 文件的转储而无需预处理从 ``cursor.fetch*`` 调用返回的数据。 在被写入之前所有其他非字符串数据都会先用 "
":func:`str` 来转转为字符串。"
#: ../../library/csv.rst:117
msgid ""
"Associate *dialect* with *name*. *name* must be a string. The dialect can "
"be specified either by passing a sub-class of :class:`Dialect`, or by "
"*fmtparams* keyword arguments, or both, with keyword arguments overriding "
"parameters of the dialect. For full details about dialects and formatting "
"parameters, see section :ref:`csv-fmt-params`."
msgstr ""
"将 *dialect* 与 *name* 关联起来。 *name* 必须是字符串。 变种的指定可以通过传入一个 :class:`Dialect` "
"的子类,或通过 *fmtparams* 关键字参数,或是两者同时传入,此时关键字参数会覆盖 dialect 形参。 "
"有关变种和格式化形参的完整细节,请参阅 :ref:`csv-fmt-params` 部分。"
#: ../../library/csv.rst:126
msgid ""
"Delete the dialect associated with *name* from the dialect registry. An "
":exc:`Error` is raised if *name* is not a registered dialect name."
msgstr "从变种注册表中删除 *name* 对应的变种。如果 *name* 不是已注册的变种名称,则抛出 :exc:`Error` 异常。"
#: ../../library/csv.rst:132
msgid ""
"Return the dialect associated with *name*. An :exc:`Error` is raised if "
"*name* is not a registered dialect name. This function returns an immutable"
" :class:`Dialect`."
msgstr ""
"返回 *name* 对应的变种。如果 *name* 不是已注册的变种名称,则抛出 :exc:`Error` 异常。该函数返回的是不可变的 "
":class:`Dialect` 对象。"
#: ../../library/csv.rst:138
msgid "Return the names of all registered dialects."
msgstr "返回所有已注册变种的名称。"
#: ../../library/csv.rst:143
msgid ""
"Returns the current maximum field size allowed by the parser. If *new_limit*"
" is given, this becomes the new limit."
msgstr "返回解析器当前允许的最大字段大小。如果指定了 *new_limit*,则它将成为新的最大字段大小。"
#: ../../library/csv.rst:147
msgid "The :mod:`csv` module defines the following classes:"
msgstr ":mod:`csv` 模块定义了以下类:"
#: ../../library/csv.rst:152
msgid ""
"Create an object that operates like a regular reader but maps the "
"information in each row to a :class:`dict` whose keys are given by the "
"optional *fieldnames* parameter."
msgstr ""
"创建一个对象,该对象在操作上类似于常规 reader,但是将每行中的信息映射到一个 :class:`dict`,该 dict 的键由 "
"*fieldnames* 可选参数给出。"
#: ../../library/csv.rst:156
msgid ""
"The *fieldnames* parameter is a :term:`sequence`. If *fieldnames* is "
"omitted, the values in the first row of file *f* will be used as the "
"fieldnames. Regardless of how the fieldnames are determined, the dictionary"
" preserves their original ordering."
msgstr ""
"*fieldnames* 参数是一个 :term:`sequence`。如果省略 *fieldnames*,则文件 *f* "
"第一行中的值将用作字段名。无论字段名是如何确定的,字典都将保留其原始顺序。"
#: ../../library/csv.rst:161
msgid ""
"If a row has more fields than fieldnames, the remaining data is put in a "
"list and stored with the fieldname specified by *restkey* (which defaults to"
" ``None``). If a non-blank row has fewer fields than fieldnames, the "
"missing values are filled-in with the value of *restval* (which defaults to "
"``None``)."
msgstr ""
"如果某一行中的字段多于字段名,则剩余数据会被放入一个列表,并与 *restkey* 所指定的字段名 (默认为 ``None``) 一起保存。 "
"如果某个非空白行的字段少于字段名,则缺失的值会使用 *restval* 的值来填充 (默认为 ``None``)。"
#: ../../library/csv.rst:167
msgid ""
"All other optional or keyword arguments are passed to the underlying "
":class:`reader` instance."
msgstr "所有其他可选或关键字参数都传递给底层的 :class:`reader` 实例。"
#: ../../library/csv.rst:170
msgid "Returned rows are now of type :class:`OrderedDict`."
msgstr "返回的行现在的类型是 :class:`OrderedDict`。"
#: ../../library/csv.rst:173
msgid "Returned rows are now of type :class:`dict`."
msgstr "现在,返回的行是 :class:`dict` 类型。"
#: ../../library/csv.rst:194
msgid ""
"Create an object which operates like a regular writer but maps dictionaries "
"onto output rows. The *fieldnames* parameter is a :mod:`sequence "
"<collections.abc>` of keys that identify the order in which values in the "
"dictionary passed to the :meth:`writerow` method are written to file *f*. "
"The optional *restval* parameter specifies the value to be written if the "
"dictionary is missing a key in *fieldnames*. If the dictionary passed to "
"the :meth:`writerow` method contains a key not found in *fieldnames*, the "
"optional *extrasaction* parameter indicates what action to take. If it is "
"set to ``'raise'``, the default value, a :exc:`ValueError` is raised. If it "
"is set to ``'ignore'``, extra values in the dictionary are ignored. Any "
"other optional or keyword arguments are passed to the underlying "
":class:`writer` instance."
msgstr ""
"创建一个对象,该对象在操作上类似常规 writer,但会将字典映射到输出行。 *fieldnames* 参数是由键组成的 :mod:`序列 "
"<collections.abc>`,它指定字典中值的顺序,这些值会按指定顺序传递给 :meth:`writerow` 方法并写入文件 *f*。 "
"如果字典缺少 *fieldnames* 中的键,则可选参数 *restval* 用于指定要写入的值。 如果传递给 :meth:`writerow` "
"方法的字典的某些键在 *fieldnames* 中找不到,则可选参数 *extrasaction* 用于指定要执行的操作。 如果将其设置为默认值 "
"``'raise'``,则会引发 :exc:`ValueError`。 如果将其设置为 ``'ignore'``,则字典中的其他键值将被忽略。 "
"所有其他可选或关键字参数都传递给底层的 :class:`writer` 实例。"
#: ../../library/csv.rst:209
msgid ""
"Note that unlike the :class:`DictReader` class, the *fieldnames* parameter "
"of the :class:`DictWriter` class is not optional."
msgstr ""
"注意,与 :class:`DictReader` 类不同,:class:`DictWriter` 类的 *fieldnames* 参数不是可选参数。"
#: ../../library/csv.rst:228
msgid ""
"The :class:`Dialect` class is a container class whose attributes contain "
"information for how to handle doublequotes, whitespace, delimiters, etc. Due"
" to the lack of a strict CSV specification, different applications produce "
"subtly different CSV data. :class:`Dialect` instances define how "
":class:`reader` and :class:`writer` instances behave."
msgstr ""
":class:`Dialect` 类是一个容器类,其属性包含有如何处理双引号、空白符、分隔符等的信息。 由于缺少严格的 CSV "
"规格描述,不同的应用程序会产生略有差别的 CSV 数据。 :class:`Dialect` 实例定义了 :class:`reader` 和 "
":class:`writer` 实例将具有怎样的行为。"
#: ../../library/csv.rst:234
msgid ""
"All available :class:`Dialect` names are returned by :func:`list_dialects`, "
"and they can be registered with specific :class:`reader` and :class:`writer`"
" classes through their initializer (``__init__``) functions like this::"
msgstr ""
"所有可用的 :class:`Dialect` 名称会由 :func:`list_dialects` 返回,并且它们可由特定的 "
":class:`reader` 和 :class:`writer` 类通过它们的初始化函数 (``__init__``) 来注册,例如::"
#: ../../library/csv.rst:247
msgid ""
"The :class:`excel` class defines the usual properties of an Excel-generated "
"CSV file. It is registered with the dialect name ``'excel'``."
msgstr ":class:`excel` 类定义了 Excel 生成的 CSV 文件的常规属性。它在变种注册表中的名称是 ``'excel'``。"
#: ../../library/csv.rst:253
msgid ""
"The :class:`excel_tab` class defines the usual properties of an Excel-"
"generated TAB-delimited file. It is registered with the dialect name "
"``'excel-tab'``."
msgstr ""
":class:`excel_tab` 类定义了 Excel 生成的、制表符分隔的 CSV 文件的常规属性。它在变种注册表中的名称是 ``'excel-"
"tab'``。"
#: ../../library/csv.rst:259
msgid ""
"The :class:`unix_dialect` class defines the usual properties of a CSV file "
"generated on UNIX systems, i.e. using ``'\\n'`` as line terminator and "
"quoting all fields. It is registered with the dialect name ``'unix'``."
msgstr ""
":class:`unix_dialect` 类定义了在 UNIX 系统上生成的 CSV 文件的常规属性,即使用 ``'\\n'`` "
"作为换行符,且所有字段都有引号包围。它在变种注册表中的名称是 ``'unix'``。"
#: ../../library/csv.rst:268
msgid "The :class:`Sniffer` class is used to deduce the format of a CSV file."
msgstr ":class:`Sniffer` 类用于推断 CSV 文件的格式。"
#: ../../library/csv.rst:270
msgid "The :class:`Sniffer` class provides two methods:"
msgstr ":class:`Sniffer` 类提供了两个方法:"
#: ../../library/csv.rst:274
msgid ""
"Analyze the given *sample* and return a :class:`Dialect` subclass reflecting"
" the parameters found. If the optional *delimiters* parameter is given, it "
"is interpreted as a string containing possible valid delimiter characters."
msgstr ""
"分析给定的 *sample* 并返回一个 :class:`Dialect` 子类,该子类中包含了分析出的格式参数。如果给出可选的 "
"*delimiters* 参数,则该参数会被解释为字符串,该字符串包含了可能的有效定界符。"
#: ../../library/csv.rst:282
msgid ""
"Analyze the sample text (presumed to be in CSV format) and return "
":const:`True` if the first row appears to be a series of column headers."
msgstr ""
#: ../../library/csv.rst:285
msgid "An example for :class:`Sniffer` use::"
msgstr "使用 :class:`Sniffer` 的示例:"
#: ../../library/csv.rst:294
msgid "The :mod:`csv` module defines the following constants:"
msgstr ":mod:`csv` 模块定义了以下常量:"
#: ../../library/csv.rst:298
msgid "Instructs :class:`writer` objects to quote all fields."
msgstr "指示 :class:`writer` 对象给所有字段加上引号。"
#: ../../library/csv.rst:303
msgid ""
"Instructs :class:`writer` objects to only quote those fields which contain "
"special characters such as *delimiter*, *quotechar* or any of the characters"
" in *lineterminator*."
msgstr ""
"指示 :class:`writer` 对象仅为包含特殊字符(例如 *定界符*、*引号字符* 或 *行结束符* 中的任何字符)的字段加上引号。"
#: ../../library/csv.rst:310
msgid "Instructs :class:`writer` objects to quote all non-numeric fields."
msgstr "指示 :class:`writer` 对象为所有非数字字段加上引号。"
#: ../../library/csv.rst:312
msgid "Instructs the reader to convert all non-quoted fields to type *float*."
msgstr "指示 reader 将所有未用引号引出的字段转换为 *float* 类型。"
#: ../../library/csv.rst:317
msgid ""
"Instructs :class:`writer` objects to never quote fields. When the current "
"*delimiter* occurs in output data it is preceded by the current *escapechar*"
" character. If *escapechar* is not set, the writer will raise :exc:`Error` "
"if any characters that require escaping are encountered."
msgstr ""
"指示 :class:`writer` 对象不使用引号引出字段。当 *定界符* 出现在输出数据中时,其前面应该有 *转义符*。如果未设置 "
"*转义符*,则遇到任何需要转义的字符时,writer 都会抛出 :exc:`Error` 异常。"
#: ../../library/csv.rst:322
msgid ""
"Instructs :class:`reader` to perform no special processing of quote "
"characters."
msgstr "指示 :class:`reader` 不对引号字符进行特殊处理。"
#: ../../library/csv.rst:324
msgid "The :mod:`csv` module defines the following exception:"
msgstr ":mod:`csv` 模块定义了以下异常:"
#: ../../library/csv.rst:329
msgid "Raised by any of the functions when an error is detected."
msgstr "该异常可能由任何发生错误的函数抛出。"
#: ../../library/csv.rst:334
msgid "Dialects and Formatting Parameters"
msgstr "变种与格式参数"
#: ../../library/csv.rst:336
msgid ""
"To make it easier to specify the format of input and output records, "
"specific formatting parameters are grouped together into dialects. A "
"dialect is a subclass of the :class:`Dialect` class having a set of specific"
" methods and a single :meth:`validate` method. When creating "
":class:`reader` or :class:`writer` objects, the programmer can specify a "
"string or a subclass of the :class:`Dialect` class as the dialect parameter."
" In addition to, or instead of, the *dialect* parameter, the programmer can"
" also specify individual formatting parameters, which have the same names as"
" the attributes defined below for the :class:`Dialect` class."
msgstr ""
"为了更容易指定输入和输出记录的格式,特定的一组格式参数组合为一个 dialect(变种)。一个 dialect 是一个 :class:`Dialect`"
" 类的子类,它具有一组特定的方法和一个 :meth:`validate` 方法。创建 :class:`reader` 或 :class:`writer`"
" 对象时,程序员可以将某个字符串或 :class:`Dialect` 类的子类指定为 dialect 参数。要想补充或覆盖 *dialect* "
"参数,程序员还可以单独指定某些格式参数,这些参数的名称与下面 :class:`Dialect` 类定义的属性相同。"
#: ../../library/csv.rst:346
msgid "Dialects support the following attributes:"
msgstr "Dialect 类支持以下属性:"
#: ../../library/csv.rst:351
msgid ""
"A one-character string used to separate fields. It defaults to ``','``."
msgstr "一个用于分隔字段的单字符,默认为 ``','``。"
#: ../../library/csv.rst:356
msgid ""
"Controls how instances of *quotechar* appearing inside a field should "
"themselves be quoted. When :const:`True`, the character is doubled. When "
":const:`False`, the *escapechar* is used as a prefix to the *quotechar*. It"
" defaults to :const:`True`."
msgstr ""
"控制出现在字段中的 *引号字符* 本身应如何被引出。当该属性为 :const:`True` 时,双写引号字符。如果该属性为 "
":const:`False`,则在 *引号字符* 的前面放置 *转义符*。默认值为 :const:`True`。"
#: ../../library/csv.rst:361
msgid ""
"On output, if *doublequote* is :const:`False` and no *escapechar* is set, "
":exc:`Error` is raised if a *quotechar* is found in a field."
msgstr ""
"在输出时,如果 *doublequote* 是 :const:`False`,且 *转义符* 未指定,且在字段中发现 *引号字符* 时,会抛出 "
":exc:`Error` 异常。"
#: ../../library/csv.rst:367
msgid ""
"A one-character string used by the writer to escape the *delimiter* if "
"*quoting* is set to :const:`QUOTE_NONE` and the *quotechar* if *doublequote*"
" is :const:`False`. On reading, the *escapechar* removes any special meaning"
" from the following character. It defaults to :const:`None`, which disables "
"escaping."
msgstr ""
"一个用于 writer 的单字符,用来在 *quoting* 设置为 :const:`QUOTE_NONE` 的情况下转义 *定界符*,在 "
"*doublequote* 设置为 :const:`False` 的情况下转义 *引号字符*。在读取时,*escapechar* "
"去除了其后所跟字符的任何特殊含义。该属性默认为 :const:`None`,表示禁用转义。"
#: ../../library/csv.rst:375
msgid ""
"The string used to terminate lines produced by the :class:`writer`. It "
"defaults to ``'\\r\\n'``."
msgstr "放在 :class:`writer` 产生的行的结尾,默认为 ``'\\r\\n'``。"
#: ../../library/csv.rst:380
msgid ""
"The :class:`reader` is hard-coded to recognise either ``'\\r'`` or ``'\\n'``"
" as end-of-line, and ignores *lineterminator*. This behavior may change in "
"the future."
msgstr ""
":class:`reader` 经过硬编码,会识别 ``'\\r'`` 或 ``'\\n'`` 作为行尾,并忽略 "
"*lineterminator*。未来可能会更改这一行为。"
#: ../../library/csv.rst:387
msgid ""
"A one-character string used to quote fields containing special characters, "
"such as the *delimiter* or *quotechar*, or which contain new-line "
"characters. It defaults to ``'\"'``."
msgstr "一个单字符,用于包住含有特殊字符的字段,特殊字符如 *定界符* 或 *引号字符* 或换行符。默认为 ``'\"'``。"
#: ../../library/csv.rst:394
msgid ""
"Controls when quotes should be generated by the writer and recognised by the"
" reader. It can take on any of the :const:`QUOTE_\\*` constants (see "
"section :ref:`csv-contents`) and defaults to :const:`QUOTE_MINIMAL`."
msgstr ""
"控制 writer 何时生成引号,以及 reader 何时识别引号。该属性可以等于任何 :const:`QUOTE_\\*` 常量(参见 "
":ref:`csv-contents` 段落),默认为 :const:`QUOTE_MINIMAL`。"
#: ../../library/csv.rst:401
msgid ""
"When :const:`True`, whitespace immediately following the *delimiter* is "
"ignored. The default is :const:`False`."
msgstr ""
#: ../../library/csv.rst:407
msgid ""
"When ``True``, raise exception :exc:`Error` on bad CSV input. The default is"
" ``False``."
msgstr "如果为 ``True``,则在输入错误的 CSV 时抛出 :exc:`Error` 异常。默认值为 ``False``。"
#: ../../library/csv.rst:411
msgid "Reader Objects"
msgstr "Reader 对象"
#: ../../library/csv.rst:413
msgid ""
"Reader objects (:class:`DictReader` instances and objects returned by the "
":func:`reader` function) have the following public methods:"
msgstr "Reader 对象(:class:`DictReader` 实例和 :func:`reader` 函数返回的对象)具有以下公开方法:"
#: ../../library/csv.rst:418
msgid ""
"Return the next row of the reader's iterable object as a list (if the object"
" was returned from :func:`reader`) or a dict (if it is a :class:`DictReader`"
" instance), parsed according to the current :class:`Dialect`. Usually you "
"should call this as ``next(reader)``."
msgstr ""
"返回 reader 的可迭代对象的下一行,它可以是一个列表(如果对象是由 :func:`reader` 返回)或字典(如果是一个 "
":class:`DictReader` 实例),根据当前 :class:`Dialect` 来解析。 通常你应当以 ``next(reader)`` "
"的形式来调用它。"
#: ../../library/csv.rst:424
msgid "Reader objects have the following public attributes:"
msgstr "Reader 对象具有以下公开属性:"
#: ../../library/csv.rst:428
msgid "A read-only description of the dialect in use by the parser."
msgstr "变种描述,只读,供解析器使用。"
#: ../../library/csv.rst:433
msgid ""
"The number of lines read from the source iterator. This is not the same as "
"the number of records returned, as records can span multiple lines."
msgstr "源迭代器已经读取了的行数。它与返回的记录数不同,因为记录可能跨越多行。"
#: ../../library/csv.rst:437
msgid "DictReader objects have the following public attribute:"
msgstr "DictReader 对象具有以下公开属性:"
#: ../../library/csv.rst:441
msgid ""
"If not passed as a parameter when creating the object, this attribute is "
"initialized upon first access or when the first record is read from the "
"file."
msgstr "字段名称。如果在创建对象时未传入字段名称,则首次访问时或从文件中读取第一条记录时会初始化此属性。"
#: ../../library/csv.rst:448
msgid "Writer Objects"
msgstr "Writer 对象"
#: ../../library/csv.rst:450
msgid ""
":class:`Writer` objects (:class:`DictWriter` instances and objects returned "
"by the :func:`writer` function) have the following public methods. A *row* "
"must be an iterable of strings or numbers for :class:`Writer` objects and a "
"dictionary mapping fieldnames to strings or numbers (by passing them through"
" :func:`str` first) for :class:`DictWriter` objects. Note that complex "
"numbers are written out surrounded by parens. This may cause some problems "
"for other programs which read CSV files (assuming they support complex "
"numbers at all)."
msgstr ""
":class:`Writer` 对象(:class:`DictWriter` 实例和 :func:`writer` "
"函数返回的对象)具有下面的公开方法。对于 :class:`Writer` 对象,*行* 必须是(一组可迭代的)字符串或数字。对于 "
":class:`DictWriter` 对象,*行* 必须是一个字典,这个字典将字段名映射为字符串或数字(数字要先经过 :func:`str` "
"转换类型)。请注意,输出的复数会有括号包围。这样其他程序读取 CSV 文件时可能会有一些问题(假设它们完全支持复数)。"
#: ../../library/csv.rst:461
msgid ""
"Write the *row* parameter to the writer's file object, formatted according "
"to the current :class:`Dialect`. Return the return value of the call to the "
"*write* method of the underlying file object."
msgstr ""
"将 *row* 形参写入到 writer 的文件对象,根据当前 :class:`Dialect` 进行格式化。 返回对下层文件对象的 *write* "
"方法的调用的返回值。"
#: ../../library/csv.rst:465
msgid "Added support of arbitrary iterables."
msgstr "开始支持任意类型的迭代器。"
#: ../../library/csv.rst:470
msgid ""
"Write all elements in *rows* (an iterable of *row* objects as described "
"above) to the writer's file object, formatted according to the current "
"dialect."
msgstr ""
"将 *rows*(即能迭代出多个上述 *row* 对象的迭代器)中的所有元素写入 writer 的文件对象,并根据当前设置的变种进行格式化。"
#: ../../library/csv.rst:474
msgid "Writer objects have the following public attribute:"
msgstr "Writer 对象具有以下公开属性:"
#: ../../library/csv.rst:479
msgid "A read-only description of the dialect in use by the writer."
msgstr "变种描述,只读,供 writer 使用。"
#: ../../library/csv.rst:482
msgid "DictWriter objects have the following public method:"
msgstr "DictWriter 对象具有以下公开方法:"
#: ../../library/csv.rst:487
msgid ""
"Write a row with the field names (as specified in the constructor) to the "
"writer's file object, formatted according to the current dialect. Return the"
" return value of the :meth:`csvwriter.writerow` call used internally."
msgstr ""
"在 writer 的文件对象中,写入一行字段名称(字段名称在构造函数中指定),并根据当前设置的变种进行格式化。本方法的返回值就是内部使用的 "
":meth:`csvwriter.writerow` 方法的返回值。"
#: ../../library/csv.rst:492
msgid ""
":meth:`writeheader` now also returns the value returned by the "
":meth:`csvwriter.writerow` method it uses internally."
msgstr "现在 :meth:`writeheader` 也返回其内部使用的 :meth:`csvwriter.writerow` 方法的返回值。"
#: ../../library/csv.rst:500
msgid "Examples"
msgstr "例子"
#: ../../library/csv.rst:502
msgid "The simplest example of reading a CSV file::"
msgstr "读取 CSV 文件最简单的一个例子::"
#: ../../library/csv.rst:510
msgid "Reading a file with an alternate format::"
msgstr "读取其他格式的文件::"
#: ../../library/csv.rst:518
msgid "The corresponding simplest possible writing example is::"
msgstr "相应最简单的写入示例是::"
#: ../../library/csv.rst:525
msgid ""
"Since :func:`open` is used to open a CSV file for reading, the file will by "
"default be decoded into unicode using the system default encoding (see "
":func:`locale.getpreferredencoding`). To decode a file using a different "
"encoding, use the ``encoding`` argument of open::"
msgstr ""
"由于使用 :func:`open` 来读取 CSV 文件,因此默认情况下,将使用系统默认编码来解码文件并转换为 unicode(请参阅 "
":func:`locale.getpreferredencoding`)。要使用其他编码来解码文件,请使用 open 的 ``encoding`` "
"参数::"
#: ../../library/csv.rst:536
msgid ""
"The same applies to writing in something other than the system default "
"encoding: specify the encoding argument when opening the output file."
msgstr "这同样适用于写入非系统默认编码的内容:打开输出文件时,指定 encoding 参数。"
#: ../../library/csv.rst:539
msgid "Registering a new dialect::"
msgstr "注册一个新的变种::"
#: ../../library/csv.rst:546
msgid ""
"A slightly more advanced use of the reader --- catching and reporting "
"errors::"
msgstr "Reader 的更高级用法——捕获并报告错误::"
#: ../../library/csv.rst:558
msgid ""
"And while the module doesn't directly support parsing strings, it can easily"
" be done::"
msgstr "尽管该模块不直接支持解析字符串,但仍可如下轻松完成::"
#: ../../library/csv.rst:567
msgid "Footnotes"
msgstr "备注"
#: ../../library/csv.rst:568
msgid ""
"If ``newline=''`` is not specified, newlines embedded inside quoted fields "
"will not be interpreted correctly, and on platforms that use ``\\r\\n`` "
"linendings on write an extra ``\\r`` will be added. It should always be "
"safe to specify ``newline=''``, since the csv module does its own "
"(:term:`universal <universal newlines>`) newline handling."
msgstr ""
"如果没有指定 ``newline=''``,则嵌入引号中的换行符将无法正确解析,并且在写入时,使用 ``\\r\\n`` 换行的平台会有多余的 "
"``\\r`` 写入。由于 csv 模块会执行自己的(:term:`通用 <universal newlines>`)换行符处理,因此指定 "
"``newline=''`` 应该总是安全的。"