bslatkin / effectivepython

Effective Python: Second Edition — Source Code and Errata for the Book
https://effectivepython.com
2.2k stars 710 forks source link

bytes.encode/str.decode -> str.encode/bytes.decode? #106

Closed hoxell closed 1 month ago

hoxell commented 2 years ago

2nd edition, Item 3: Know the Difference between bytes and str, in the last paragraph on page 9, it reads:

This fails because the file was opened in read text mode ('r') instead of read binary mode ('rb'). When a handle is in text mode, it uses the system's default text encoding to interpret binary data using bytes.encode (for writing) and str.decode (for reading) methods.

I think it's supposed be:

[...] str.encode (for writing) and bytes.decode (for reading) methods.

bslatkin commented 1 month ago

Thank you for the report! Yes, this was wrong. Deduping this with #93