Python's equivalent for R's dput() function

后端 未结 4 1782
遇见更好的自我
遇见更好的自我 2020-12-20 11:16

Is there any function in python similar to dput() function in R?

4条回答
  •  渐次进展
    2020-12-20 11:36

    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 to import json before to make the json 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 persistent dict.
    • marshal.dump(): Not sure when you'd ever need that.

提交回复
热议问题