Pickling
Aim: Implement
a Program to implement the concept of pickling.
Algorithm:
1.Start
2.Create a dictionary
3.Save a dictionary into a pickle file.
4. Load the dictionary
back from the pickle file.
5.Dispaly the
dictionary.
6.Stop
Program:
# Save a dictionary into a pickle file.
import pickle
favorite_color = { "lion":
"yellow", "kitty": "red" }
pickle.dump( favorite_color, open(
"save.p", "wb" ) )
# Load the dictionary
back from the pickle file.
import pickle
favorite_color = pickle.load( open(
"save.p", "rb" ) )
print favorite_color
# favorite_color is now { "lion":
"yellow", "kitty": "red" }
Output:
{ "lion":
"yellow", "kitty": "red" }
0 Comments:
Post a Comment