I would like to save it some readable format so pickle i wouldn't like to
use.
I am thinking of using YAML or TOML both seem more comprehendable than XML
or JSON,
I'd probably go with JSON -- it mapps more directly to pyton objects (i.e.
dicts), so very little code to write to use for persistence.
Also -- if you don't need to interface with non-python apps -- you could
use what I cal PySON -- Python literals.
you can read them with ast.literal_eval, which is pretty secure (i.e. only
reads literals, not arbitrary Python code)
Also, there is a JSON-pickle:
https://jsonpickle.github.io/
Which gives you all (Most) of the easy of use of pickle, but a JSON format.
(and the security risks of pickle...)
However, I would still wanted to experiment with user-defined persistence
objects.
You can write a generic persistence system really easily that supports
simple classes quite easily:
Simply write the __dict__ and the __class__ to your file (as JSON, or TOML,
or...) and then you can re-construct an instance with the __class__, and
re-populate it with the contents of __class__.
"simple" classes in this case means that all attributes are regular
build-tin python objects (the ones with literals).
It could, of course be extended to do nested objects of custom types, but
then you're getting into more work...
-CHB
···
On Fri, Jan 13, 2017 at 12:32 AM, Nick D. <nikos7am@gmail.com> wrote:
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker@noaa.gov