Beispiel #1
0
def test_tojsonarrays():

    # exercise function
    table = (('foo', 'bar'), ('a', 1), ('b', 2), ('c', 2))
    f = NamedTemporaryFile(delete=False)
    tojsonarrays(table, f.name)
    result = json.load(f)
    assert len(result) == 3
    assert result[0][0] == 'a'
    assert result[0][1] == 1
    assert result[1][0] == 'b'
    assert result[1][1] == 2
    assert result[2][0] == 'c'
    assert result[2][1] == 2
Beispiel #2
0
def test_tojsonarrays():

    # exercise function
    table = (('foo', 'bar'),
             ('a', 1),
             ('b', 2),
             ('c', 2))
    f = NamedTemporaryFile(delete=False, mode='r')
    tojsonarrays(table, f.name)
    result = json.load(f)
    assert len(result) == 3
    assert result[0][0] == 'a'
    assert result[0][1] == 1
    assert result[1][0] == 'b'
    assert result[1][1] == 2
    assert result[2][0] == 'c'
    assert result[2][1] == 2
Beispiel #3
0
tojson(table, 'example.json')
# check what it did
with open('example.json') as f:
    print f.read()


# tojsonarrays

table = [['foo', 'bar'],
         ['a', 1],
         ['b', 2],
         ['c', 2]]

from petl import tojsonarrays, look
look(table)
tojsonarrays(table, 'example.json')
# check what it did
with open('example.json') as f:
    print f.read()


# mergesort

table1 = (('foo', 'bar'),
          ('A', 9),
          ('C', 2),
          ('D', 10),
          ('A', 6),
          ('F', 1))
table2 = (('foo', 'bar'),
          ('B', 3),
Beispiel #4
0
tojson(table, 'example.json')
# check what it did
with open('example.json') as f:
    print f.read()


# tojsonarrays

table = [['foo', 'bar'],
         ['a', 1],
         ['b', 2],
         ['c', 2]]

from petl import tojsonarrays, look
look(table)
tojsonarrays(table, 'example.json')
# check what it did
with open('example.json') as f:
    print f.read()


# mergesort

table1 = (('foo', 'bar'),
          ('A', 9),
          ('C', 2),
          ('D', 10),
          ('A', 6),
          ('F', 1))
table2 = (('foo', 'bar'),
          ('B', 3),
Beispiel #5
0
         {"foo": "c", "bar": 2}]
table1 = etl.fromdicts(dicts)
table1


# tojson()
##########

import petl as etl
table1 = [['foo', 'bar'],
          ['a', 1],
          ['b', 2],
          ['c', 2]]
etl.tojson(table1, 'example.json', sort_keys=True)
# check what it did
print(open('example.json').read())


# tojsonarrays()
################

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