@@ -158,6 +158,18 @@ The :mod:`csv` module defines the following classes:
158158 the optional *restval * parameter. Any other optional or keyword arguments
159159 are passed to the underlying :class: `reader ` instance.
160160
161+ A short usage example::
162+
163+ >>> import csv
164+ >>> with open('names.csv') as csvfile:
165+ ... reader = csv.DictReader(csvfile)
166+ ... for row in reader:
167+ ... print(row['first_name'], row['last_name'])
168+ ...
169+ Baked Beans
170+ Lovely Spam
171+ Wonderful Spam
172+
161173
162174.. class :: DictWriter(csvfile, fieldnames, restval='', extrasaction='raise', \
163175 dialect='excel', *args, **kwds)
@@ -180,6 +192,19 @@ The :mod:`csv` module defines the following classes:
180192 objects are not ordered, there is not enough information available to deduce
181193 the order in which the row should be written to the *csvfile *.
182194
195+ A short usage example::
196+
197+ import csv
198+
199+ with open('names.csv', 'w') as csvfile:
200+ fieldnames = ['first_name', 'last_name']
201+ writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
202+
203+ writer.writeheader()
204+ writer.writerow({'first_name': 'Baked', 'last_name': 'Beans'})
205+ writer.writerow({'first_name': 'Lovely', 'last_name': 'Spam'})
206+ writer.writerow({'first_name': 'Wonderful', 'last_name': 'Spam'})
207+
183208
184209.. class :: Dialect
185210
0 commit comments