File: csv.py

package info (click to toggle)
python-petl 1.7.17-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 2,224 kB
  • sloc: python: 22,617; makefile: 109; xml: 9
file content (33 lines) | stat: -rw-r--r-- 637 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from __future__ import division, print_function, absolute_import


# fromcsv()
###########

import petl as etl
import csv
# set up a CSV file to demonstrate with
table1 = [['foo', 'bar'],
          ['a', 1],
          ['b', 2],
          ['c', 2]]
with open('example.csv', 'w') as f:
    writer = csv.writer(f)
    writer.writerows(table1)

# now demonstrate the use of fromcsv()
table2 = etl.fromcsv('example.csv')
table2


# tocsv()
#########

import petl as etl
table1 = [['foo', 'bar'],
          ['a', 1],
          ['b', 2],
          ['c', 2]]
etl.tocsv(table1, 'example.csv')
# look what it did
print(open('example.csv').read())