Answer
There are several options for serializing Python objects to files:
json.dump()
stores the data in JSON format. It is very read- and editable, but can only store lists, dicts, strings, numbers, booleans, so no compound objects. You need toimport json
before to make thejson
module available.pickle.dump()
can store most objects.
Less common:
- The
shelve
module stores multiple Python objects in a DBM database, mostly acting like a persistentdict
. marshal.dump()
: Not sure when you'd ever need that.
No comments:
Post a Comment