I kept the module pickle in my directory. Now, I want to store the variable i.e. Arpan in a created file called spdict.data So, when i enter the code as follows:
import pickle
Arpan = "My name is Arpan"
fh = open("spdict.data","w")
pickle.dump(Arpan,fh)
fh.close()
I would expect the variable Arpan to get stored, but I get the following error.
Traceback (most recent call last): File "C:\Users\Home\AppData\Local\Programs\Python\Python36-32\IDLE scripts for bioinfo book\File handling\test1 reading fasta.py", line 173, in pickle.dump(Arpan,fh) TypeError: write() argument must be str, not bytes
Also, when I enter the program
import pickle
Arpan = {"One":1,"Two":2,"Three":3}
fh = open("spdict.data","w")
pickle.dump(Arpan,fh)
fh.close()
Then also, following error comes:
Traceback (most recent call last): File "C:\Users\Home\AppData\Local\Programs\Python\Python36-32\IDLE scripts for bioinfo book\File handling\test1 reading fasta.py", line 173, in pickle.dump(Arpan,fh) TypeError: write() argument must be str, not bytes
Please help.. My python version is 3.6.4