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
86148178
Kaydet (Commit)
86148178
authored
Şub 23, 2010
tarafından
Dirkjan Ochtman
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fix #1537721: add writeheader() method to csv.DictWriter.
Reviewed by skip.montanaro and thomas.wouters.
üst
92bd059c
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
20 additions
and
0 deletions
+20
-0
csv.rst
Doc/library/csv.rst
+10
-0
csv.py
Lib/csv.py
+4
-0
test_csv.py
Lib/test/test_csv.py
+4
-0
NEWS
Misc/NEWS
+2
-0
No files found.
Doc/library/csv.rst
Dosyayı görüntüle @
86148178
...
...
@@ -424,6 +424,16 @@ Writer objects have the following public attribute:
A read-only description of the dialect in use by the writer.
DictWriter objects have the following public method:
.. method:: DictWriter.writeheader()
Write a row with the field names (as specified in the constructor).
.. versionadded:: 2.7
.. _csv-examples:
Examples
...
...
Lib/csv.py
Dosyayı görüntüle @
86148178
...
...
@@ -132,6 +132,10 @@ class DictWriter:
self
.
extrasaction
=
extrasaction
self
.
writer
=
writer
(
f
,
dialect
,
*
args
,
**
kwds
)
def
writeheader
(
self
):
header
=
dict
(
zip
(
self
.
fieldnames
,
self
.
fieldnames
))
self
.
writerow
(
header
)
def
_dict_to_list
(
self
,
rowdict
):
if
self
.
extrasaction
==
"raise"
:
wrong_fields
=
[
k
for
k
in
rowdict
if
k
not
in
self
.
fieldnames
]
...
...
Lib/test/test_csv.py
Dosyayı görüntüle @
86148178
...
...
@@ -598,8 +598,12 @@ class TestDictFields(unittest.TestCase):
fileobj
=
os
.
fdopen
(
fd
,
"w+b"
)
try
:
writer
=
csv
.
DictWriter
(
fileobj
,
fieldnames
=
[
"f1"
,
"f2"
,
"f3"
])
writer
.
writeheader
()
fileobj
.
seek
(
0
)
self
.
assertEqual
(
fileobj
.
readline
(),
"f1,f2,f3
\r\n
"
)
writer
.
writerow
({
"f1"
:
10
,
"f3"
:
"abc"
})
fileobj
.
seek
(
0
)
fileobj
.
readline
()
# header
self
.
assertEqual
(
fileobj
.
read
(),
"10,,abc
\r\n
"
)
finally
:
fileobj
.
close
()
...
...
Misc/NEWS
Dosyayı görüntüle @
86148178
...
...
@@ -53,6 +53,8 @@ Library
- Issue #5801: removed spurious empty lines in wsgiref.
- Issue #1537721: Add a writeheader() method to csv.DictWriter.
Extension Modules
-----------------
...
...
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