Back to index

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

List of all members.

Public Member Functions

def __init__
def __iter__
def fieldnames
def fieldnames
def __next__

Public Attributes

 restkey
 restval
 reader
 dialect
 line_num

Private Attributes

 _fieldnames

Detailed Description

Definition at line 79 of file csv.py.


Constructor & Destructor Documentation

def csv.DictReader.__init__ (   self,
  f,
  fieldnames = None,
  restkey = None,
  restval = None,
  dialect = "excel",
  args,
  kwds 
)

Definition at line 81 of file csv.py.

00081 
00082                  dialect="excel", *args, **kwds):
00083         self._fieldnames = fieldnames   # list of keys for the dict
00084         self.restkey = restkey          # key to catch long rows
00085         self.restval = restval          # default value for short rows
00086         self.reader = reader(f, dialect, *args, **kwds)
00087         self.dialect = dialect
00088         self.line_num = 0

Here is the caller graph for this function:


Member Function Documentation

def csv.DictReader.__iter__ (   self)

Definition at line 89 of file csv.py.

00089 
00090     def __iter__(self):
00091         return self

def csv.DictReader.__next__ (   self)

Definition at line 106 of file csv.py.

00106 
00107     def __next__(self):
00108         if self.line_num == 0:
00109             # Used only for its side effect.
00110             self.fieldnames
00111         row = next(self.reader)
00112         self.line_num = self.reader.line_num
00113 
00114         # unlike the basic reader, we prefer not to return blanks,
00115         # because we will typically wind up with a dict full of None
00116         # values
00117         while row == []:
00118             row = next(self.reader)
00119         d = dict(zip(self.fieldnames, row))
00120         lf = len(self.fieldnames)
00121         lr = len(row)
00122         if lf < lr:
00123             d[self.restkey] = row[lf:]
00124         elif lf > lr:
00125             for key in self.fieldnames[lr:]:
00126                 d[key] = self.restval
00127         return d
00128 

Here is the call graph for this function:

Here is the caller graph for this function:

def csv.DictReader.fieldnames (   self)

Definition at line 93 of file csv.py.

00093 
00094     def fieldnames(self):
00095         if self._fieldnames is None:
00096             try:
00097                 self._fieldnames = next(self.reader)
00098             except StopIteration:
00099                 pass
00100         self.line_num = self.reader.line_num
00101         return self._fieldnames

Here is the caller graph for this function:

def csv.DictReader.fieldnames (   self,
  value 
)

Definition at line 103 of file csv.py.

00103 
00104     def fieldnames(self, value):
00105         self._fieldnames = value

Here is the call graph for this function:


Member Data Documentation

Definition at line 82 of file csv.py.

Definition at line 86 of file csv.py.

Definition at line 87 of file csv.py.

Definition at line 85 of file csv.py.

Definition at line 83 of file csv.py.

Definition at line 84 of file csv.py.


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