Save the object to a file with pickle

Library: pickle

import pickle

Save the object to a file

mydict = {1: 'Pochi',
          2: 'Taro',
          3: 'Jiro'}
with open('xxx.dump', 'w') as f:
    pickle.dump(mydict, f)

Read an object from a file

with open('xxx.dump', 'r') as f:
    mydict_load = pickle.load(f)
print mydict_load  # {1: 'Pochi', 2: 'Taro', 3: 'Jiro'}

Recommended Posts

Save the object to a file with pickle
[Python] You can save an object to a file by using the pickle module.
How to make a command to read the configuration file with pyramid
How to read a CSV file with Python 2/3
I want to write to a file with Python
The file edited with vim was readonly but I want to save it
Attempt to launch another .exe and save the console output to a text file
Save an array of numpy to a wav file using the wave module
How to create a submenu with the [Blender] plugin
Convert a text file with hexadecimal values to a binary file
How to convert a class object to a dictionary with SQLAlchemy
Transit to the update screen with the Django a tag
Upload a file to Dropbox
Parse JSON file to object
How to put a hyperlink to "file: // hogehoge" with sphinx-> pdf
[python] Change the image file name to a serial number
Finding a solution to the N-Queen problem with a genetic algorithm (2)
Change the standard output destination to a file in Python
Access the file with a relative path from the execution script.
Probably the easiest way to create a pdf with Python3
The first step to creating a serverless application with Zappa
A story about how to deal with the CORS problem
The usual way to add a Kernel with Jupyter Notebook
[Python] The first step to making a game with Pyxel
Save images on the web to Drive with Python (Colab)
I tried to divide the file into folders with Python
Try to decipher the garbled attachment file name with Python
Finding a solution to the N-Queen problem with a genetic algorithm (1)
Save & load data with joblib, pickle
Extract the xz file with python
[Python] Write to csv file with Python
Save the binary file in Python
Follow the file hierarchy with fts
Build a deb file with Docker
Output to csv file with Python
Output cell to file with Colaboratory
Download the file deployed with appcfg.py
A light introduction to object detection
Save a YAML-formatted file in PyYAML
Open the file with the default app
How to create a config file
Create a file uploader with Django
Save the results of crawling with Scrapy to the Google Data Store
Save the result of the life game as a gif with python
[Introduction to Python] How to split a character string with the split function
Process Splunk execution results using Python and save to a file
Conditional branch due to the existence of a shell script file
[Introduction to StyleGAN] I played with "The Life of a Man" ♬
Correspondence analysis of sentences with COTOHA API and save to file
Save the Pydrive authentication file in a different directory from the script
How to output the output result of the Linux man command to a file
Read a file in Python with a relative path from the program
I wanted to solve the ABC164 A ~ D problem with Python
Write a script to calculate the distance with Elasticsearch 5 system painless
The idea of feeding the config file with a python file instead of yaml
[ROS2] How to play a bag file with python format launch
Get OCTA simulation conditions from a file and save with pandas
Try adding a wall to your IFC file with IfcOpenShell python
How to send a request to the DMM (FANZA) API with python
Create a REST API to operate dynamodb with the Django REST Framework
Tweet the weather forecast with a bot