def __iter__(self): with self.source.open('rb') as buf: if PY2: codec = getcodec(self.encoding) fr = codec.streamreader(buf, errors=self.errors) else: fr = io.TextIOWrapper(buf, encoding=self.encoding, errors=self.errors, newline='') # Skip headers and footers before trying to parse rows f = iter(fr) if self.skiprows: f = skip(f, self.skiprows) if self.skipfooter: f = skiplast(f, self.skipfooter) try: if self.header is not None: yield tuple(self.header) for raw_line in f: yield self._rowparser(raw_line) finally: if not PY2: fr.detach()
look(table1) table2 = pushheader(table1, ['foo', 'bar']) look(table2) # skip table1 = [['#aaa', 'bbb', 'ccc'], ['#mmm'], ['foo', 'bar'], ['a', 1], ['b', 2]] from petl import skip, look look(table1) table2 = skip(table1, 2) look(table2) # skipcomments table1 = [['##aaa', 'bbb', 'ccc'], ['##mmm',], ['#foo', 'bar'], ['##nnn', 1], ['a', 1], ['b', 2]] from petl import skipcomments, look look(table1) table2 = skipcomments(table1, '##')
table1 = [['foo'], ['a', 1, True], ['b', 2, False]] table2 = etl.extendheader(table1, ['bar', 'baz']) table2 # pushheader() ############## import petl as etl table1 = [['a', 1], ['b', 2]] table2 = etl.pushheader(table1, ['foo', 'bar']) table2 # skip() ######### import petl as etl table1 = [['#aaa', 'bbb', 'ccc'], ['#mmm'], ['foo', 'bar'], ['a', 1], ['b', 2]] table2 = etl.skip(table1, 2) table2
import petl from language import Language filename = 'languages.csv' csv = petl.fromcsv(filename) languages = [] print print("PETL Table") print("----------") x = 0 for row in petl.skip(csv, 1): if x < 5: print(row) x += 1 for row in petl.skip(csv, 1): languages.append(Language(row)) print print("Languages Array") print("----------------") print(languages) print print("PROOF") print("-----") for l in languages: print("Name: " + str(l.programming_language)) print