Unicode vs. Bytes: Fundamental Text Handling Overhaul
Python 3 fundamentally separated text (`str` for Unicode) from binary data (`bytes`), contrasting Python 2 where `str` was ambiguous (could be bytes or text) and `unicode` was a separate type, necessitating explicit encoding/decoding for I/O and string operations.
The top 3
- Python 2's Text Handling: Top 3 Ambiguity Pitfalls: In Python 2, the `str` type ambiguously served as both text and bytes, causing frequent `UnicodeDecodeError` and `UnicodeEncodeError` when implicitly mixing them, a major source of developer frustration.
- Python 3's Core: `str` for Text, `bytes` for Binary: Python 3 established a clear separation between `str` (Unicode text characters) and `bytes` (raw 8-bit binary data), necessitating explicit `encode()` and `decode()` methods for conversions between them.
- Python 2 to 3: Top 3 Text Migration Gotchas: Major migration challenges included implicit byte/string concatenation, using incorrect text/binary modes for file I/O, and assumptions about default ASCII encodings, frequently resulting in `TypeError` or `UnicodeError`.
Sources
Open the full topic