AXON: Step by step


In [8]:
import axon
from pprint import pprint

Load top-level lis of objects:


In [13]:
text = """
{red:0 green:32 blue:64}
{red:32 green:64 blue:0}
{red:64 green:0 blue:32}
"""
vals = axon.loads(text)
pprint(vals)
print(axon.dumps(vals, pretty=1))


[{'blue': 64, 'green': 32, 'red': 0},
 {'blue': 0, 'green': 64, 'red': 32},
 {'blue': 32, 'green': 0, 'red': 64}]
{ blue: 64
  green: 32
  red: 0}
{ blue: 0
  green: 64
  red: 32}
{ blue: 32
  green: 0
  red: 64}

Load top-level ordered map:


In [14]:
text = """
a: [1 2 3]
b: [4 5 6]
c: [7 8 9]
"""
vals = axon.loads(text)
pprint(vals)
print(axon.dumps(vals, pretty=1))


OrderedDict([('a', [1, 2, 3]), ('b', [4, 5, 6]), ('c', [7, 8, 9])])
a: [1 2 3]
b: [4 5 6]
c: [7 8 9]

Load JSON-like objects:


In [16]:
text = """
{
  int: [0 1000 123456789123456789123456789]
  float: [3.141528 -0 ? ∞ -∞]
  decimal: [10000D 3.141528D -0D ?D ∞D -∞D]
  bool: (true false)
  dict: {red:10 green:32 blue:0}
  odict: [red:10 green:32 blue:0]
  list: [1 2 3]
  node: message {from:"nick" to:"mark" "Hello"}
}
"""
vals = axon.loads(text)
val = vals[0]
pprint(val)
print(axon.dumps(vals, pretty=1))


{'bool': (True, False),
 'decimal': [Decimal('10000'),
             Decimal('3.141528'),
             Decimal('-0'),
             Decimal('NaN'),
             Decimal('Infinity'),
             Decimal('-Infinity')],
 'dict': {'blue': 0, 'green': 32, 'red': 10},
 'float': [3.141528, 0, nan, inf, -inf],
 'int': [0, 1000, 123456789123456789123456789],
 'list': [1, 2, 3],
 'node': message{from: 'nick', to: 'mark' 'Hello'},
 'odict': OrderedDict([('red', 10), ('green', 32), ('blue', 0)])}
{ bool: (true false)
  decimal: [10000D 3.141528D -0D ?D ∞D -∞D]
  dict: {
    blue: 0
    green: 32
    red: 10}
  float: [3.141528 0 ? ∞ -∞]
  int: [0 1000 123456789123456789123456789]
  list: [1 2 3]
  node: message
    from: "nick"
    to: "mark"
    "Hello"
  odict: [
    blue: 0
    green: 32
    red: 10]}

In [ ]: