Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
0a421a28
Kaydet (Commit)
0a421a28
authored
Eki 21, 2016
tarafından
INADA Naoki
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #18219: Optimize csv.DictWriter for large number of columns.
Patch by Mariatta Wijaya.
üst
4510e6de
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
28 additions
and
5 deletions
+28
-5
csv.rst
Doc/library/csv.rst
+6
-4
csv.py
Lib/csv.py
+1
-1
test_csv.py
Lib/test/test_csv.py
+18
-0
NEWS
Misc/NEWS
+3
-0
No files found.
Doc/library/csv.rst
Dosyayı görüntüle @
0a421a28
...
...
@@ -195,10 +195,12 @@ The :mod:`csv` module defines the following classes:
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'`` 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.
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.
Note that unlike the :class:`DictReader` class, the *fieldnames* parameter
of the :class:`DictWriter` is not optional. Since Python's :class:`dict`
...
...
Lib/csv.py
Dosyayı görüntüle @
0a421a28
...
...
@@ -145,7 +145,7 @@ class DictWriter:
def
_dict_to_list
(
self
,
rowdict
):
if
self
.
extrasaction
==
"raise"
:
wrong_fields
=
[
k
for
k
in
rowdict
if
k
not
in
self
.
fieldnames
]
wrong_fields
=
rowdict
.
keys
()
-
self
.
fieldnames
if
wrong_fields
:
raise
ValueError
(
"dict contains fields not in fieldnames: "
+
", "
.
join
([
repr
(
x
)
for
x
in
wrong_fields
]))
...
...
Lib/test/test_csv.py
Dosyayı görüntüle @
0a421a28
...
...
@@ -626,6 +626,24 @@ class TestDictFields(unittest.TestCase):
self
.
assertNotIn
(
"'f2'"
,
exception
)
self
.
assertIn
(
"1"
,
exception
)
def
test_typo_in_extrasaction_raises_error
(
self
):
fileobj
=
StringIO
()
self
.
assertRaises
(
ValueError
,
csv
.
DictWriter
,
fileobj
,
[
'f1'
,
'f2'
],
extrasaction
=
"raised"
)
def
test_write_field_not_in_field_names_raise
(
self
):
fileobj
=
StringIO
()
writer
=
csv
.
DictWriter
(
fileobj
,
[
'f1'
,
'f2'
],
extrasaction
=
"raise"
)
dictrow
=
{
'f0'
:
0
,
'f1'
:
1
,
'f2'
:
2
,
'f3'
:
3
}
self
.
assertRaises
(
ValueError
,
csv
.
DictWriter
.
writerow
,
writer
,
dictrow
)
def
test_write_field_not_in_field_names_ignore
(
self
):
fileobj
=
StringIO
()
writer
=
csv
.
DictWriter
(
fileobj
,
[
'f1'
,
'f2'
],
extrasaction
=
"ignore"
)
dictrow
=
{
'f0'
:
0
,
'f1'
:
1
,
'f2'
:
2
,
'f3'
:
3
}
csv
.
DictWriter
.
writerow
(
writer
,
dictrow
)
self
.
assertEqual
(
fileobj
.
getvalue
(),
"1,2
\r\n
"
)
def
test_read_dict_fields
(
self
):
with
TemporaryFile
(
"w+"
)
as
fileobj
:
fileobj
.
write
(
"1,2,abc
\r\n
"
)
...
...
Misc/NEWS
Dosyayı görüntüle @
0a421a28
...
...
@@ -20,6 +20,9 @@ Core and Builtins
Library
-------
- Issue #18219: Optimize csv.DictWriter for large number of columns.
Patch by Mariatta Wijaya.
- Issue #28448: Fix C implemented asyncio.Future didn't work on Windows.
- Issue #28480: Fix error building socket module when multithreading is
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment