Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Private Member Functions
csv.DictWriter Class Reference

List of all members.

Public Member Functions

def __init__
def writeheader
def writerow
def writerows

Public Attributes

 fieldnames
 restval
 extrasaction
 writer

Private Member Functions

def _dict_to_list

Detailed Description

Definition at line 129 of file csv.py.


Constructor & Destructor Documentation

def csv.DictWriter.__init__ (   self,
  f,
  fieldnames,
  restval = "",
  extrasaction = "raise",
  dialect = "excel",
  args,
  kwds 
)

Definition at line 131 of file csv.py.

00131 
00132                  dialect="excel", *args, **kwds):
00133         self.fieldnames = fieldnames    # list of keys for the dict
00134         self.restval = restval          # for writing short dicts
00135         if extrasaction.lower() not in ("raise", "ignore"):
00136             raise ValueError("extrasaction (%s) must be 'raise' or 'ignore'"
00137                              % extrasaction)
00138         self.extrasaction = extrasaction
00139         self.writer = writer(f, dialect, *args, **kwds)

Here is the caller graph for this function:


Member Function Documentation

def csv.DictWriter._dict_to_list (   self,
  rowdict 
) [private]

Definition at line 144 of file csv.py.

00144 
00145     def _dict_to_list(self, rowdict):
00146         if self.extrasaction == "raise":
00147             wrong_fields = [k for k in rowdict if k not in self.fieldnames]
00148             if wrong_fields:
00149                 raise ValueError("dict contains fields not in fieldnames: "
00150                                  + ", ".join(wrong_fields))
00151         return [rowdict.get(key, self.restval) for key in self.fieldnames]

Here is the caller graph for this function:

Definition at line 140 of file csv.py.

00140 
00141     def writeheader(self):
00142         header = dict(zip(self.fieldnames, self.fieldnames))
00143         self.writerow(header)

Here is the call graph for this function:

def csv.DictWriter.writerow (   self,
  rowdict 
)

Definition at line 152 of file csv.py.

00152 
00153     def writerow(self, rowdict):
00154         return self.writer.writerow(self._dict_to_list(rowdict))

Here is the call graph for this function:

Here is the caller graph for this function:

def csv.DictWriter.writerows (   self,
  rowdicts 
)

Definition at line 155 of file csv.py.

00155 
00156     def writerows(self, rowdicts):
00157         rows = []
00158         for rowdict in rowdicts:
00159             rows.append(self._dict_to_list(rowdict))
00160         return self.writer.writerows(rows)
00161 
00162 # Guard Sniffer's type checking against builds that exclude complex()
try:

Here is the call graph for this function:


Member Data Documentation

Definition at line 137 of file csv.py.

Definition at line 132 of file csv.py.

Definition at line 133 of file csv.py.

Definition at line 138 of file csv.py.


The documentation for this class was generated from the following file: