Note: This code and documentation are incomplete.
-
namedtuple
- Docs: https://docs.python.org/2/library/collections.html#collections.namedtuple
- Source: https://hg.python.org/cpython/file/2.7/Lib/collections.py#l305
- The
rename
argument is interesting. It replaces key names that meet certain criteria, (repeated, is a reserved word, etc.) with the index number instead. A useful idea for my own classes that allow names that haven't been predefined. However, rather than using an index number, use an altered form of the name, like "_unsafeKey_%s".
-
Namespace
- Docs: https://docs.python.org/2/library/argparse.html#argparse.Namespace
- Source: https://hg.python.org/cpython/file/2.7/Lib/argparse.py#l1153
- I chose to use Namespace as the base for my class because I could see how to extend it to allow access to nonexistent attributes to return
None
instead of throwing an exception.
-
Inspriations
-
Namespace solution: http://stackoverflow.com/a/35920523/543738
I see using Namespace as a weird hack, since this code isn't related to argparse at all.
-
Quick/dirty pickle: http://stackoverflow.com/a/33270983/543738
I'd like to use some ideas from this to remove dependency on Namespace.
-
https://github.com/jsonpickle/jsonpickle
Interesting, but it seems to require specifying a backend and passing along an object_hook in order to handle object attributes. It ends up being more code than using only the json module.
-