Inserts the given column into the matrix. Missing rows at the end (bottom) will be filled with the default value.
(self, j, column, default=None, field=None)
| 1985 | return not self.__eq__(self, columns) |
| 1986 | |
| 1987 | def insert(self, j, column, default=None, field=None): |
| 1988 | """ Inserts the given column into the matrix. |
| 1989 | Missing rows at the end (bottom) will be filled with the default value. |
| 1990 | """ |
| 1991 | try: column = [v for v in column] |
| 1992 | except: |
| 1993 | raise TypeError, "Datasheet.columns.insert(x): x must be list" |
| 1994 | column = column + [default] * (len(self._datasheet) - len(column)) |
| 1995 | if len(column) > len(self._datasheet): |
| 1996 | self._datasheet.extend([[None]] * (len(column)-len(self._datasheet))) |
| 1997 | for i, row in enumerate(self._datasheet): |
| 1998 | row.insert(j, column[i]) |
| 1999 | self._datasheet.__dict__["_m"] += 1 # Increase column count. |
| 2000 | # Add a new header. |
| 2001 | if self._datasheet.fields is not None: |
| 2002 | self._datasheet.fields += [(None, None)] * (len(self) - len(self._datasheet.fields) - 1) |
| 2003 | self._datasheet.fields.insert(j, field or (None, None)) |
| 2004 | |
| 2005 | def append(self, column, default=None, field=None): |
| 2006 | self.insert(len(self), column, default, field) |