Exemplo n.º 1
0
 def test_rows_as_ordered_dict(self):
     rows = [OrderedDict([('s', 'life'), ('n', 1.0)]),
             OrderedDict([('s', 'universe'), ('n', 3.14)]),
             OrderedDict([('s', 'everything'), ('n', 42.0)])]
     fp = BytesIO()
     xport.from_rows(rows, fp)
     fp.seek(0)
     dup = list(xport.DictReader(fp))
     self.assertEqual(rows, dup)
Exemplo n.º 2
0
 def test_from_rows(self, library):
     ds = next(iter(library.values()))
     rows = list(ds.itertuples(index=None, name=None))
     fp = BytesIO()
     with pytest.warns(DeprecationWarning):
         xport.from_rows(rows, fp)
     fp.seek(0)
     result = next(iter(xport.v56.load(fp).values()))
     assert (result.values == ds.values).all(axis=None)
Exemplo n.º 3
0
 def test_rows_as_ordered_dict(self):
     rows = [
         OrderedDict([('s', 'life'), ('n', 1.0)]),
         OrderedDict([('s', 'universe'), ('n', 3.14)]),
         OrderedDict([('s', 'everything'), ('n', 42.0)])
     ]
     fp = BytesIO()
     xport.from_rows(rows, fp)
     fp.seek(0)
     dup = list(xport.DictReader(fp))
     self.assertEqual(rows, dup)
Exemplo n.º 4
0
 def roundtrip(self, rows):
     fp = BytesIO()
     xport.from_rows(rows, fp)
     fp.seek(0)
     duplicate = xport.to_rows(fp)
     self.assertEqual(rows, duplicate)
Exemplo n.º 5
0
 def roundtrip(self, rows):
     fp = BytesIO()
     xport.from_rows(rows, fp)
     fp.seek(0)
     duplicate = xport.to_rows(fp)
     self.assertEqual(rows, duplicate)
Exemplo n.º 6
0
import xport
import csv
import sys

fields = [] 
rows = [] 

with open(sys.argv[1], 'r') as csvfile:  
    csvreader = csv.reader(csvfile) 
      
    fields = next(csvreader)
  
    for row in csvreader: 
        rows.append(row) 

records = []
for row in rows:
	i=0
	dict = {}
	for col in row:
		dict[fields[i]] = col
		i = i + 1
	records.append(dict)

with open(sys.argv[2], 'wb') as f:
    xport.from_rows(records, f)