Monday 17 October 2016

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



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



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 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.


No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...