Repository navigation
Expand file tree
/
Copy pathcsv.po
More file actions
1093 lines (960 loc) · 48.5 KB
/
Copy pathcsv.po
File metadata and controls
1093 lines (960 loc) · 48.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
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 Python Software Foundation
# This file is distributed under the same license as the Python package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
# Translators:
# Rafael Fontenelle <rffontenelle@gmail.com>, 2026
# Freesand Leo <yuqinju@163.com>, 2026
# Alpha Du <alphanow@gmail.com>, 2026
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: Python 3.14\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2026-10-21 19:19+0000\n"
"PO-Revision-Date: 2026-05-08 17:17+0000\n"
"Last-Translator: Alpha Du <alphanow@gmail.com>, 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/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 ":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 :ref:`reader object <reader-objects>` that will process lines from "
"the given *csvfile*. A csvfile must be an iterable of strings, each in the "
"reader's defined csv format. A csvfile is most commonly a file-like object "
"or list. 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 ""
"返回一个 :ref:`reader 对象 <reader-objects>`,该对象将处理给定 *csvfile* 中的行。 csvfile "
"必须是一个包含字符串的可迭代对象,使用 reader 所定义的 csv 格式。 csvfile 通常是一个文件型对象或列表。 如果 *csvfile* "
"是一个文件对象,则打开它时应设置 ``newline=''``. [1]_ 给定可选 *dialect* 形参将被用于定义一组专属于特定 CSV "
"变种的形参。 它可以是 :class:`Dialect` 类的子类的实例,或是 :func:`list_dialects` 函数所返回的字符串之一。 "
"另一个可选关键字形参 *fmtparams* 可被用来覆盖当前变种中的单个格式形参。 有关变种和格式设置形参的完整细节,请参阅 :ref:`csv-"
"fmt-params` 一节。"
#: ../../library/csv.rst:72
msgid ""
"Each row read from the csv file is returned as a list of strings. No "
"automatic data type conversion is performed unless the "
":data:`QUOTE_NONNUMERIC` format option is specified (in which case unquoted "
"fields are transformed into floats)."
msgstr ""
"从 csv 文件读取的每一行都将返回为一个字符串列表。 除非指定了 :data:`QUOTE_NONNUMERIC` "
"格式选项(在这种情况下未加引号的字段会被转换为浮点数),否则不会执行自动数据类型转换。"
#: ../../library/csv.rst:76 ../../library/csv.rst:113
#: ../../library/csv.rst:196 ../../library/csv.rst:242
msgid "A short usage example::"
msgstr "一个简短的用法示例::"
#: ../../library/csv.rst:78
msgid ""
">>> import csv\n"
">>> with open('eggs.csv', newline='') as csvfile:\n"
"... spamreader = csv.reader(csvfile, delimiter=' ', quotechar='|')\n"
"... for row in spamreader:\n"
"... print(', '.join(row))\n"
"Spam, Spam, Spam, Spam, Spam, Baked Beans\n"
"Spam, Lovely Spam, Wonderful Spam"
msgstr ""
">>> import csv\n"
">>> with open('eggs.csv', newline='') as csvfile:\n"
"... spamreader = csv.reader(csvfile, delimiter=' ', quotechar='|')\n"
"... for row in spamreader:\n"
"... print(', '.join(row))\n"
"Spam, Spam, Spam, Spam, Spam, Baked Beans\n"
"Spam, Lovely Spam, Wonderful Spam"
#: ../../library/csv.rst:86
msgid "where :file:`eggs.csv` contains:"
msgstr "其中 :file:`eggs.csv` 包含:"
#: ../../library/csv.rst:88 ../../library/csv.rst:124
msgid ""
"Spam Spam Spam Spam Spam |Baked Beans|\n"
"Spam |Lovely Spam| |Wonderful Spam|"
msgstr ""
"Spam Spam Spam Spam Spam |Baked Beans|\n"
"Spam |Lovely Spam| |Wonderful Spam|"
#: ../../library/csv.rst:96
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 :meth:`~io.TextIOBase.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* 可以是任何具有 "
":meth:`~io.TextIOBase.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:115
msgid ""
"import csv\n"
"with open('eggs.csv', 'w', newline='') as csvfile:\n"
" spamwriter = csv.writer(csvfile, delimiter=' ',\n"
" quotechar='|', quoting=csv.QUOTE_MINIMAL)\n"
" spamwriter.writerow(['Spam'] * 5 + ['Baked Beans'])\n"
" spamwriter.writerow(['Spam', 'Lovely Spam', 'Wonderful Spam'])"
msgstr ""
"import csv\n"
"with open('eggs.csv', 'w', newline='') as csvfile:\n"
" spamwriter = csv.writer(csvfile, delimiter=' ',\n"
" quotechar='|', quoting=csv.QUOTE_MINIMAL)\n"
" spamwriter.writerow(['Spam'] * 5 + ['Baked Beans'])\n"
" spamwriter.writerow(['Spam', 'Lovely Spam', 'Wonderful Spam'])"
#: ../../library/csv.rst:122
msgid "which writes :file:`eggs.csv` containing:"
msgstr "这将写入 :file:`eggs.csv` 其中包含:"
#: ../../library/csv.rst:132
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:141
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:147
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:153
msgid "Return the names of all registered dialects."
msgstr "返回所有已注册变种的名称。"
#: ../../library/csv.rst:159
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:163
msgid "The :mod:`!csv` module defines the following classes:"
msgstr ":mod:`!csv` 模块定义了下列类:"
#: ../../library/csv.rst:168
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:172
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 and will be omitted from the results. If *fieldnames* is "
"provided, they will be used and the first row will be included in the "
"results. Regardless of how the fieldnames are determined, the dictionary "
"preserves their original ordering."
msgstr ""
"*fieldnames* 形参是一个 :term:`sequence`。 如果省略 *fieldnames*,则文件 *f* "
"第一行中的值将用作字段名并将从结果中去除。 如果提供了 *fieldnames*,它们将被使用而第一行将包括在结果中。 "
"无论字段名是如何确定的,字典都将保留其原始顺序。"
#: ../../library/csv.rst:179
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:185
msgid ""
"All other optional or keyword arguments are passed to the underlying "
":class:`reader` instance."
msgstr "所有其他可选或关键字参数都传递给底层的 :class:`reader` 实例。"
#: ../../library/csv.rst:188 ../../library/csv.rst:240
msgid ""
"If the argument passed to *fieldnames* is an iterator, it will be coerced to"
" a :class:`list`."
msgstr "如果传给 *fieldnames* 的参数是一个迭代器,它将被强制转换为 :class:`list`。"
#: ../../library/csv.rst:190
msgid "Returned rows are now of type :class:`OrderedDict`."
msgstr "返回的行现在的类型是 :class:`OrderedDict`。"
#: ../../library/csv.rst:193
msgid "Returned rows are now of type :class:`dict`."
msgstr "现在,返回的行是 :class:`dict` 类型。"
#: ../../library/csv.rst:198
msgid ""
">>> import csv\n"
">>> with open('names.csv', newline='') as csvfile:\n"
"... reader = csv.DictReader(csvfile)\n"
"... for row in reader:\n"
"... print(row['first_name'], row['last_name'])\n"
"...\n"
"Eric Idle\n"
"John Cleese\n"
"\n"
">>> print(row)\n"
"{'first_name': 'John', 'last_name': 'Cleese'}"
msgstr ""
">>> import csv\n"
">>> with open('names.csv', newline='') as csvfile:\n"
"... reader = csv.DictReader(csvfile)\n"
"... for row in reader:\n"
"... print(row['first_name'], row['last_name'])\n"
"...\n"
"Eric Idle\n"
"John Cleese\n"
"\n"
">>> print(row)\n"
"{'first_name': 'John', 'last_name': 'Cleese'}"
#: ../../library/csv.rst:210
msgid "where :file:`names.csv` contains:"
msgstr "其中 :file:`names.csv` 包含:"
#: ../../library/csv.rst:212
msgid ""
"first_name,last_name\n"
"Eric,Idle\n"
"John,Cleese"
msgstr ""
"first_name,last_name\n"
"Eric,Idle\n"
"John,Cleese"
#: ../../library/csv.rst:222
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:`~csvwriter.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:`~csvwriter.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:`~csvwriter.writerow` 方法并写入文件 *f* 的值的顺序。 "
"如果字典没有 *fieldnames* 中的键,则可选的 *restval* 形参将指明要写入的值。 如果传递给 "
":meth:`~csvwriter.writerow` 方法包含的键在 *fieldnames* 中找不到,则可选的 *extrasaction* "
"形参将指明要执行的操作。 如果将其设为默认值 ``'raise'``,则会引发 :exc:`ValueError`。 如果将其设为 "
"``'ignore'``,则字典中额外的值将被忽略。 任何其他可选或关键字参数都将被传递给下层的 :class:`writer` 实例。"
#: ../../library/csv.rst:237
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:244
msgid ""
"import csv\n"
"\n"
"with open('names.csv', 'w', newline='') as csvfile:\n"
" fieldnames = ['first_name', 'last_name']\n"
" writer = csv.DictWriter(csvfile, fieldnames=fieldnames)\n"
"\n"
" writer.writeheader()\n"
" writer.writerow({'first_name': 'Baked', 'last_name': 'Beans'})\n"
" writer.writerow({'first_name': 'Lovely', 'last_name': 'Spam'})\n"
" writer.writerow({'first_name': 'Wonderful', 'last_name': 'Spam'})"
msgstr ""
"import csv\n"
"\n"
"with open('names.csv', 'w', newline='') as csvfile:\n"
" fieldnames = ['first_name', 'last_name']\n"
" writer = csv.DictWriter(csvfile, fieldnames=fieldnames)\n"
"\n"
" writer.writeheader()\n"
" writer.writerow({'first_name': 'Baked', 'last_name': 'Beans'})\n"
" writer.writerow({'first_name': 'Lovely', 'last_name': 'Spam'})\n"
" writer.writerow({'first_name': 'Wonderful', 'last_name': 'Spam'})"
#: ../../library/csv.rst:255
msgid "which writes :file:`names.csv` containing:"
msgstr "这将写入 :file:`names.csv` 其中包含:"
#: ../../library/csv.rst:257
msgid ""
"first_name,last_name\n"
"Baked,Beans\n"
"Lovely,Spam\n"
"Wonderful,Spam"
msgstr ""
"first_name,last_name\n"
"Baked,Beans\n"
"Lovely,Spam\n"
"Wonderful,Spam"
#: ../../library/csv.rst:267
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:273
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:277
msgid ""
"import csv\n"
"\n"
"with open('students.csv', 'w', newline='') as csvfile:\n"
" writer = csv.writer(csvfile, dialect='unix')"
msgstr ""
"import csv\n"
"\n"
"with open('students.csv', 'w', newline='') as csvfile:\n"
" writer = csv.writer(csvfile, dialect='unix')"
#: ../../library/csv.rst:285
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:291
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:297
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:306
msgid "The :class:`Sniffer` class is used to deduce the format of a CSV file."
msgstr ":class:`Sniffer` 类用于推断 CSV 文件的格式。"
#: ../../library/csv.rst:308
msgid "The :class:`Sniffer` class provides two methods:"
msgstr ":class:`Sniffer` 类提供了两个方法:"
#: ../../library/csv.rst:312
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:317
msgid ""
"If several delimiters fit the sample equally well --- for example if both "
"``','`` and ``';'`` split every row consistently --- the delimiters listed "
"in the :attr:`~Sniffer.preferred` attribute are preferred, in that order, no"
" matter how many times each of them occurs."
msgstr ""
"如果多个定界符对样本的适用程度相同——例如 ``','`` 和 ``';'`` 都能一致地拆分每一行——则优先选用在 "
":attr:`~Sniffer.preferred` 属性中按顺序列出的定界符,无论它们各自出现的次数如何。"
#: ../../library/csv.rst:325
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. "
"Inspecting each column, one of two key criteria will be considered to "
"estimate if the sample contains a header:"
msgstr ""
"分析 sample 文本(假定为 CSV 格式),如果发现其首行为一组列标题则返回 :const:`True`。 "
"在检查每一列时,将考虑是否满足两个关键标准之一来估计 sample 是否包含标题:"
#: ../../library/csv.rst:330
msgid "the second through n-th rows contain numeric values"
msgstr "第二至第 n 行包含数字值"
#: ../../library/csv.rst:331
msgid ""
"the second through n-th rows contain strings where at least one value's "
"length differs from that of the putative header of that column."
msgstr "第二至第 n 行包含字符串值,其中至少有一个值的长度与该列预期标题的长度不同。"
#: ../../library/csv.rst:334
msgid ""
"Twenty-one rows after the header are sampled; if more than half of the "
"columns + rows meet the criteria, :const:`True` is returned."
msgstr "对标题行之后的 21 行进行采样;如果超过半数的列和行满足条件,则返回 :const:`True`。"
#: ../../library/csv.rst:339
msgid ""
"This method is a rough heuristic and may produce both false positives and "
"negatives."
msgstr "此方法是一个粗略的启发式方式,有可能产生假正例和假反例。"
#: ../../library/csv.rst:342
msgid "The :class:`Sniffer` class has the following attribute:"
msgstr ":class:`Sniffer` 类具有以下属性:"
#: ../../library/csv.rst:346
msgid ""
"The list of the delimiters preferred for breaking ties, in the order of "
"preference. It can be modified. Its initial value is ``[',', '\\t', ';', ' "
"', ':']``."
msgstr "用于分开连接的首选分隔符列表,按优先级排序。 该列表可以被修改。 其初始值为 ``[',', '\\t', ';', ' ', ':']``。"
#: ../../library/csv.rst:351
msgid "An example for :class:`Sniffer` use::"
msgstr "使用 :class:`Sniffer` 的示例::"
#: ../../library/csv.rst:353
msgid ""
"with open('example.csv', newline='') as csvfile:\n"
" dialect = csv.Sniffer().sniff(csvfile.read(1024))\n"
" csvfile.seek(0)\n"
" reader = csv.reader(csvfile, dialect)\n"
" # ... process CSV file contents here ..."
msgstr ""
"with open('example.csv', newline='') as csvfile:\n"
" dialect = csv.Sniffer().sniff(csvfile.read(1024))\n"
" csvfile.seek(0)\n"
" reader = csv.reader(csvfile, dialect)\n"
" # ... 在此处理 CSV 文件内容 ..."
#: ../../library/csv.rst:362
msgid "The :mod:`!csv` module defines the following constants:"
msgstr ":mod:`!csv` 模块定义了下列常量:"
#: ../../library/csv.rst:366
msgid "Instructs :class:`writer` objects to quote all fields."
msgstr "指示 :class:`writer` 对象给所有字段加上引号。"
#: ../../library/csv.rst:371
msgid ""
"Instructs :class:`writer` objects to only quote those fields which contain "
"special characters such as *delimiter*, *quotechar*, ``'\\r'``, ``'\\n'`` or"
" any of the characters in *lineterminator*. If *doublequote* is "
":const:`False` and *escapechar* is set, the *quotechar* is escaped instead "
"of causing the field to be quoted."
msgstr ""
"指示 :class:`writer` 对象仅对包含特殊字符的字段进行加引号处理,例如 *delimiter* 、 *quotechar* 、 "
"``'\\r'`` 、 ``'\\n'`` 或 *lineterminator* 中的任何字符。 如果 *doublequote* 为 "
":const:`False` 且设置了 *escapechar* ,则 *quotechar* 会被转义而不是导致该字段被加上引号。"
#: ../../library/csv.rst:380
msgid "Instructs :class:`writer` objects to quote all non-numeric fields."
msgstr "指示 :class:`writer` 对象为所有非数字字段加上引号。"
#: ../../library/csv.rst:382
msgid ""
"Instructs :class:`reader` objects to convert all non-quoted fields to type "
":class:`float`."
msgstr "指示 :class:`reader` 对象将所有未加引号的字段转换为 :class:`float` 类型。"
#: ../../library/csv.rst:385
msgid ""
"Some numeric types, such as :class:`bool`, :class:`~fractions.Fraction`, or "
":class:`~enum.IntEnum`, have a string representation that cannot be "
"converted to :class:`float`. They cannot be read in the "
":data:`QUOTE_NONNUMERIC` and :data:`QUOTE_STRINGS` modes."
msgstr ""
"某些数字类型,如 :class:`bool`, :class:`~fractions.Fraction` 或 "
":class:`~enum.IntEnum`,具有不可被转换为 :class:`float` 的字符串表示形式。 它们无法在 "
":data:`QUOTE_NONNUMERIC` 和 :data:`QUOTE_STRINGS` 模式下被读取。"
#: ../../library/csv.rst:393
msgid ""
"Instructs :class:`writer` objects to never quote fields. When the current "
"*delimiter*, *quotechar*, *escapechar*, ``'\\r'``, ``'\\n'`` or any of the "
"characters in *lineterminator* 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. "
"Set *quotechar* to ``None`` to prevent its escaping."
msgstr ""
"指示 :class:`writer` 对象不对字段加引号。 在现有的 *delimiter*, *quotechar*, *escapechar*, "
"``'\\r'``, ``'\\n'`` 或 *lineterminator* 中的任何字符出现在输出数据中的时候它前面会添加当前的 "
"*escapechar*。 如果未设置*escapechar*,则在遇到任何需要转义的字符时 writer 都会引发 :exc:`Error`。 将 "
"*quotechar* 设为 ``None`` 以避免进行转义。"
#: ../../library/csv.rst:401
msgid ""
"Instructs :class:`reader` objects to perform no special processing of quote "
"characters."
msgstr "指示 :class:`reader` 对象不对引号字符执行特殊处理。"
#: ../../library/csv.rst:405
msgid ""
"Instructs :class:`writer` objects to quote all fields which are not "
"``None``. This is similar to :data:`QUOTE_ALL`, except that if a field "
"value is ``None`` an empty (unquoted) string is written."
msgstr ""
"指示 :class:`writer` 对象为所有不为 ``None`` 的字段加引号。 这类似于 "
":data:`QUOTE_ALL`,区别是如果一个字段值为 ``None`` 则会写入一个(不带引号的)空字符串。"
#: ../../library/csv.rst:409
msgid ""
"Instructs :class:`reader` objects to interpret an empty (unquoted) field as "
"``None`` and to otherwise behave as :data:`QUOTE_ALL`."
msgstr ""
"指示 :class:`reader` 对象将(不带引号的)空字段解读为 ``None`` 并在其他情况下采取与 :data:`QUOTE_ALL` "
"相同的行为。"
#: ../../library/csv.rst:416
msgid ""
"Instructs :class:`writer` objects to always place quotes around fields which"
" are strings. This is similar to :data:`QUOTE_NONNUMERIC`, except that if a"
" field value is ``None`` an empty (unquoted) string is written."
msgstr ""
"指示 :class:`writer` 对象总是为字符串字段加引号。 这类似于 :data:`QUOTE_NONNUMERIC`,区别是如果一个字段值为 "
"``None`` 则会写入一个(不带引号的)空字符串。"
#: ../../library/csv.rst:420
msgid ""
"Instructs :class:`reader` objects to interpret an empty (unquoted) string as"
" ``None`` and to otherwise behave as :data:`QUOTE_NONNUMERIC`."
msgstr ""
"指示 :class:`reader` 对象将(不带引号的)空字符串解读为 ``None`` 并在其他情况下采取与 "
":data:`QUOTE_NONNUMERIC` 相同的行为。"
#: ../../library/csv.rst:425
msgid "The :mod:`!csv` module defines the following exception:"
msgstr ":mod:`!csv` 模块定义了以下异常:"
#: ../../library/csv.rst:430
msgid "Raised by any of the functions when an error is detected."
msgstr "该异常可能由任何发生错误的函数抛出。"
#: ../../library/csv.rst:435
msgid "Dialects and Formatting Parameters"
msgstr "变种与格式参数"
#: ../../library/csv.rst:437
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 containing various "
"attributes describing the format of the CSV file. 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` 类的一个子类,它包含多个用于描述 CSV 文件的格式的属性。 当创建 :class:`reader` 或 "
":class:`writer` 对象时,程序员可以指定一个字符串或 :class:`Dialect` 类的子类作为 dialect 形参。 作为对 "
"*dialect* 形参的补充或替代,程序员还可以指定单独的格式化形参,它们的名称与 :class:`Dialect` 类所定义的以下属性相同。"
#: ../../library/csv.rst:447
msgid "Dialects support the following attributes:"
msgstr "Dialect 类支持以下属性:"
#: ../../library/csv.rst:452
msgid ""
"A one-character string used to separate fields. It defaults to ``','``."
msgstr "一个用于分隔字段的单字符,默认为 ``','``。"
#: ../../library/csv.rst:457
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:462
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:468
msgid ""
"A one-character string used by the writer to escape characters that require "
"escaping:"
msgstr "被 writer 用来对需要转义的字符进行转义的单字符字符串:"
#: ../../library/csv.rst:471
msgid ""
"the *delimiter*, the *quotechar*, ``'\\r'``, ``'\\n'`` and any of the "
"characters in *lineterminator* are escaped if *quoting* is set to "
":const:`QUOTE_NONE`;"
msgstr ""
"如果 *quoting* 被设为 :const:`QUOTE_NONE` 则 *delimiter*, *quotechar*, ``'\\r'``, "
"``'\\n'`` 以及 *lineterminator* 中的任何字符都会被转义;"
#: ../../library/csv.rst:474
msgid "the *quotechar* is escaped if *doublequote* is :const:`False`;"
msgstr "如果 *doublequote* 为 :const:`False` 则 *quotechar* 会被转义;"
#: ../../library/csv.rst:475
msgid "the *escapechar* itself."
msgstr "*escapechar* 本身。"
#: ../../library/csv.rst:477
msgid ""
"On reading, the *escapechar* removes any special meaning from the following "
"character. It defaults to :const:`None`, which disables escaping."
msgstr "在读取时,*escapechar* 将从以下字符中去除任何特殊含义。 它默认为 :const:`None`,表示禁用转义。"
#: ../../library/csv.rst:480
msgid ""
"Previously the *escapechar* itself was not escaped, which lost it on "
"reading."
msgstr "在之前的版本中, *escapechar* 本身未被转义,这导致在读取时丢失它。"
#: ../../library/csv.rst:484
msgid "An empty *escapechar* is not allowed."
msgstr "不允许空的 *escapechar*。"
#: ../../library/csv.rst:489
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:494
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:501
msgid ""
"A one-character string used to quote fields containing special characters, "
"such as the *delimiter* or the *quotechar*, or which contain new-line "
"characters (``'\\r'``, ``'\\n'`` or any of the characters in "
"*lineterminator*). It defaults to ``'\"'``. Can be set to ``None`` to "
"prevent escaping ``'\"'`` if *quoting* is set to :const:`QUOTE_NONE`."
msgstr ""
"一个单字符,用于对包含特殊字符的字段加引号,这样的特殊字符有 *delimiter* 或 *quotechar*,或者包含换行符 (``'\\r'``,"
" ``'\\n'`` 或 *lineterminator* 中的任意字符)。 默认值为 ``'\"'``。 当 *quoting* 设为 "
":const:`QUOTE_NONE` 时可被设为 ``None`` 以防止转义 ``'\"'``。"
#: ../../library/csv.rst:508
msgid "An empty *quotechar* is not allowed."
msgstr "不允许空的 *quotechar*。"
#: ../../library/csv.rst:513
msgid ""
"Controls when quotes should be generated by the writer and recognised by the"
" reader. It can take on any of the :ref:`QUOTE_\\* constants <csv-"
"constants>` and defaults to :const:`QUOTE_MINIMAL` if *quotechar* is not "
"``None``, and :const:`QUOTE_NONE` otherwise."
msgstr ""
"控制引号何时应由 writer 生成并由 reader 识别。 它可以接受任意 :ref:`QUOTE_\\* 常量 <csv-constants>` "
"并且如果 *quotechar* 不为 ``None`` 则默认为 :const:`QUOTE_MINIMAL`,否则为 "
":const:`QUOTE_NONE`。"
#: ../../library/csv.rst:521
msgid ""
"When :const:`True`, spaces immediately following the *delimiter* are "
"ignored. The default is :const:`False`. When combining ``delimiter=' '`` "
"with ``skipinitialspace=True``, unquoted empty fields are not allowed."
msgstr ""
"当 :const:`True` 时,紧跟在 *delimiter* 后的空格将被忽略。默认值为 :const:`False`。当同时使用 "
"``delimiter=' '`` 和 ``skipinitialspace=True`` 时,不允许出现未加引号的空字段。"
#: ../../library/csv.rst:528
msgid ""
"When ``True``, raise exception :exc:`Error` on bad CSV input. The default is"
" ``False``."
msgstr "如果为 ``True``,则在输入错误的 CSV 时抛出 :exc:`Error` 异常。默认值为 ``False``。"
#: ../../library/csv.rst:534
msgid "Reader Objects"
msgstr "Reader 对象"
#: ../../library/csv.rst:536
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:541
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:547
msgid "Reader objects have the following public attributes:"
msgstr "Reader 对象具有以下公开属性:"
#: ../../library/csv.rst:551
msgid "A read-only description of the dialect in use by the parser."
msgstr "变种描述,只读,供解析器使用。"
#: ../../library/csv.rst:556
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:560
msgid "DictReader objects have the following public attribute:"
msgstr "DictReader 对象具有以下公开属性:"
#: ../../library/csv.rst:564
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:571
msgid "Writer Objects"
msgstr "Writer 对象"
#: ../../library/csv.rst:573
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` 对象,*row* 必须是字符串或数字的可迭代对象,而对于 "
":class:`DictWriter` 对象则是一个将字段名映射到字符串或数字 (会先将其传给 :func:`str`) 的字典。 "
"请注意在写入复数时会用圆括号括起来。 这可能会给其他读取 CSV 文件的程序带来一些问题 (假定它们确实支持复数)。"
#: ../../library/csv.rst:584
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:588
msgid "Added support of arbitrary iterables."
msgstr "开始支持任意可迭代对象。"
#: ../../library/csv.rst:593
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:597
msgid "Writer objects have the following public attribute:"
msgstr "Writer 对象具有以下公开属性:"
#: ../../library/csv.rst:602
msgid "A read-only description of the dialect in use by the writer."
msgstr "变种描述,只读,供 writer 使用。"
#: ../../library/csv.rst:605
msgid "DictWriter objects have the following public method:"
msgstr "DictWriter 对象具有以下公开方法:"
#: ../../library/csv.rst:610
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:615
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:623
msgid "Examples"
msgstr "例子"
#: ../../library/csv.rst:625
msgid "The simplest example of reading a CSV file::"
msgstr "读取 CSV 文件最简单的一个例子::"
#: ../../library/csv.rst:627
msgid ""
"import csv\n"
"with open('some.csv', newline='') as f:\n"
" reader = csv.reader(f)\n"
" for row in reader:\n"
" print(row)"
msgstr ""
"import csv\n"
"with open('some.csv', newline='') as f:\n"
" reader = csv.reader(f)\n"
" for row in reader:\n"
" print(row)"
#: ../../library/csv.rst:633
msgid "Reading a file with an alternate format::"
msgstr "读取其他格式的文件::"
#: ../../library/csv.rst:635
msgid ""
"import csv\n"
"with open('passwd', newline='') as f:\n"
" reader = csv.reader(f, delimiter=':', quoting=csv.QUOTE_NONE)\n"
" for row in reader:\n"
" print(row)"
msgstr ""
"import csv\n"
"with open('passwd', newline='') as f:\n"
" reader = csv.reader(f, delimiter=':', quoting=csv.QUOTE_NONE)\n"
" for row in reader:\n"
" print(row)"
#: ../../library/csv.rst:641
msgid "The corresponding simplest possible writing example is::"
msgstr "相应最简单的写入示例是::"
#: ../../library/csv.rst:643
msgid ""
"import csv\n"
"with open('some.csv', 'w', newline='') as f:\n"
" writer = csv.writer(f)\n"
" writer.writerows(someiterable)"
msgstr ""
"import csv\n"
"with open('some.csv', 'w', newline='') as f:\n"
" writer = csv.writer(f)\n"
" writer.writerows(someiterable)"
#: ../../library/csv.rst:648
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.getencoding`). To decode a file using a different encoding, "
"use the ``encoding`` argument of open::"
msgstr ""
"由于 :func:`open` 被用来打开 CSV 文件供读取,因此在默认情况下将使用系统默认编码格式 (参见 "
":func:`locale.getencoding`) 把文件解码至 unicode。 要使用其他编码格式来解码文件,请使用 open 的 "
"``encoding`` 参数::"
#: ../../library/csv.rst:653
msgid ""
"import csv\n"
"with open('some.csv', newline='', encoding='utf-8') as f:\n"
" reader = csv.reader(f)\n"
" for row in reader:\n"
" print(row)"
msgstr ""
"import csv\n"
"with open('some.csv', newline='', encoding='utf-8') as f:\n"
" reader = csv.reader(f)\n"
" for row in reader:\n"
" print(row)"
#: ../../library/csv.rst:659
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:662
msgid "Registering a new dialect::"