Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in Python by (16.4k points)
I have glanced through the data that the Python docs give, however I'm still somewhat confused. Could someone post example code that would compose another document at that point use pickle to dump a dictionary into it?

1 Answer

0 votes
by (26.4k points)

Try the Following code:

import pickle

a = {'hello': 'world'}

with open('filename.pickle', 'wb') as handle:

    pickle.dump(a, handle, protocol=pickle.HIGHEST_PROTOCOL)

with open('filename.pickle', 'rb') as handle:

    b = pickle.load(handle)

print a == b

Want to become a expert in Python? Join the python course fast!

For more details, do check out the below video tutorial...

Related questions

0 votes
1 answer
asked Mar 1, 2021 in Python by Rekha (2.2k points)
0 votes
1 answer
asked Oct 11, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer
0 votes
1 answer
asked Oct 10, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer
asked Jul 10, 2019 in Python by Sammy (47.6k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...