objict

Objecjs that behave like JavaScript objects.


License
GPL-3.0
Install
pip install objict==0.1

Documentation

NOTE: This is not abandoned code, it's just that is so simple, it really doesn't need much maintenance. Still, any issues will be treated with due diligency.

objict objects behave like JavaScript objects, whose attributes can be also accessed as dictionaty keys. That's a slightly complicated way to say:

o = objict()
o.a = 1
assert o['a'] == 1
o['b'] = 2
assert o.b == 2

objicts can be created like any other dict, but it will convert dict values into objicts:

o = objict({'a': {'b': 1}})
assert o.a.b == 1
assert o['a'].b == 1
assert o.a['b'] == 1
assert o['a']['b'] == 1

This means that you can convert json strings to objicts easily. As for dump()ing, due to inconsistencies betwwen the Python-based and C-based encoders, you must do this:

o = objict({'a': {'b': 1}})
import json.encoder
json.encoder.c_make_encoder = None
assert json.dumps(o) == '{"a": {"b": 1}}'

or this:

o = objict({'a': {'b': 1}})
assert json.dumps(dict(o.items())) == '{"a": {"b": 1}}'

Finally, the objects behave like any other dict.