Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6336099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:59:02+00:00 2026-05-24T18:59:02+00:00

Are there simple ways to store a dictionary (or multiple dictionaries) in, for example,

  • 0

Are there simple ways to store a dictionary (or multiple dictionaries) in, for example, a JSON or pickle file?

For example, if I have some data like:

data = {}
data ['key1'] = "keyinfo"
data ['key2'] = "keyinfo2"

How can I save it in a file, and then later load it back in to the program from the file?


JSON and Pickle can also be used to store more complex structured data. This question may also include answers that are specific to the case of a simple dictionary like the one described. For more general approaches, see How can I write structured data to a file and then read it back into the same structure later?. Note that the technique of converting the data to storable data is called serialization, and re-creating the data structure is called deserialization; storing the data for later use is called persistence.

See also What do files actually contain, and how are they "read"? What is a "format" and why should I worry about them? for some theory about how files work, and why structured data cannot just be written into and read from files directly.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T18:59:03+00:00Added an answer on May 24, 2026 at 6:59 pm

    Pickle save:

    try:
        import cPickle as pickle
    except ImportError:  # Python 3.x
        import pickle
    
    with open('data.p', 'wb') as fp:
        pickle.dump(data, fp, protocol=pickle.HIGHEST_PROTOCOL)
    

    See the pickle module documentation for additional information regarding the protocol argument.

    Pickle load:

    with open('data.p', 'rb') as fp:
        data = pickle.load(fp)
    

    JSON save:

    import json
    
    with open('data.json', 'w') as fp:
        json.dump(data, fp)
    

    Supply extra arguments, like sort_keys or indent, to get a pretty result. The argument sort_keys will sort the keys alphabetically and indent will indent your data structure with indent=N spaces.

    json.dump(data, fp, sort_keys=True, indent=4)
    

    JSON load:

    with open('data.json', 'r') as fp:
        data = json.load(fp)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to store some relatively simple stuff in XML in a cascading manner.
I'm wondering if there are any simple ways to get a list of all
Comparing string in C# is pretty simple. In fact there are several ways to
There is simple JSON serialization module with name simplejson which easily serializes Python objects
So, I am looking at a number of ways to store my configuration data.
I have an array of constant data like following: enum Language {GERMAN=LANG_DE, ENGLISH=LANG_EN, ...};
Are there simple libraries out there (.NET and Java) that are able to validate
There is simple cipher that translates number to series of . ( ) In
Is there a simple way of getting a HTML textarea and an input type=text
Is there a simple way to cache MySQL queries in PHP or failing that,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.