1. Home
  2. Docs
  3. Python-DataScience
  4. Save and Load
  5. JSON or Pickle ?

JSON or Pickle ?

In my personal experience, I suggest using JSON if:

  • You want a human-readable file,
  • A file type that is compatible across multiple technologies without very much implementation overhead.
  • An easily editable file (as it can simply be a text file).

I would suggest using Pickle if:

  • The majority of the project will be written in python.
  • The dictionary is likely to become very large/complex or rolled into a larger class.
  • A non-human readable file is required.
  • A file that is difficult to edit without prior knowledge of its construction.

Based on the situation you touch upon in your question, JSON would be the more beneficial choice.

Cite from:
https://stackoverflow.com/questions/46525235/save-dict-to-pickle-or-write-to-file

theory原理

数据的Serialize and Deserialize 序列化和反序列化

My solution (with pickle)

Was this article helpful to you? Yes No

How can we help?

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.