0

I read "How to think like a Computer Scientist. Learning with Python." book. So I usually have no difficulties to interpret examples from python2 to python3, but at chapter 11 Files & Exceptions I encountered this snippet

>>> import pickle >>> f = open("test.pck", "w") >>> pickle.dump(12.3, f) >>> pickle.dump([1,2,3], f) >>> f.close() 

which when I evaluate it using Python 3.5.2 gives this error

Traceback (most recent call last): File "/(myDirs)/files.py", line 3, in <module> pickle.dump(3.14, f) TypeError: write() argument must be str, not bytes 

I am not a good docs reader, so if you can help me to solve this riddle I would be grateful.

1 Answer 1

1

You need to open the file in binary mode.

In line 2:

f = open("test.pck", "wb") 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.