示例#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)
示例#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)
示例#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)
示例#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)
示例#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)
示例#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)