Sample usage of Python pickle


import pickle

sample_dic = {'key1': 1, 'key2': 2, 'key3': 3}
sample_dic['key4'] = 4
f = open('sample.binaryfile','wb')
pickle.dump(sample_dic,f)
f.close


f = open('sample.binaryfile','rb')

new_dic = pickle.load(f)

print(new_dic)
print(new_dic['key4'])


Recommended Posts

Sample usage of Python pickle
Usage of Python locals ()
[Python] Correct usage of map
Basic usage of Python f-string
[Python] Correct usage of join
[python] Correct usage of if statement
Introduction of Python
Python closure sample
Basics of Python ①
Basics of python ①
Non-logical operator usage of or in python
Introduction of Python
[Python] Class type and usage of datetime module
[Introduction to Python] Basic usage of lambda expressions
List of python modules
Unification of Python environment
Copy of python preferences
Basics of Python scraping basics
Summary of pyenv usage
Basic usage of flask-classy
[python] behavior of argmax
Basic usage of Jinja2
the zen of Python
Ajax + Python + PostgreSQL sample
python decorator usage notes
Basic usage of SQLAlchemy
Python Pickle format notes
[Python] pytest-mock Usage notes
Basic knowledge of Python
Sober trivia of python3
Summary of Python arguments
Basics of python: Output
Installation of matplotlib (Python 3.3.2)
Application of Python 3 vars
Various processing of Python
Python --Simple multi-thread sample
List of sample program distribution sites for python books
Python --Explanation and usage summary of the top 24 packages
[Introduction to Python] Basic usage of the library matplotlib
Sample of getting module name and class name in Python
Sample data created with python
Super basic usage of pytest
Towards the retirement of Python2
Summary of Python3 list operations
Using multiple versions of Python on Mac OS X (2) Usage
A simple sample of pivot_table.
Python --Quick start of logging
Recommendation of binpacking library of python
I just changed the sample source of Python a little.
Basic usage of PySimple GUI
[python] Value of function object (?)
Python standard unittest usage notes
Construction of Python local development environment Part 2 (pyenv-virtualenv, pip usage)
python * args, ** kwargs Usage notes
Sample source of Observer pattern realized by Java, PHP, Python
Automatic update of Python module
Sample image of Python API server for EC2 (public AMI)
Python --Check type of values
Static analysis of Python programs
About various encodings of Python 3
Equivalence of objects in Python