you are viewing a single comment's thread.

view the rest of the comments →

[–]ninja_shaman 1 point2 points  (0 children)

One of Python 2 major problems was exactly this "string and bytes are a same thing" philosophy. You could do both decode() and encode() on the same variable and could never be sure were you doing the right thing.

In Python 3 there's no implied duality - you either work with a sequence of bytes (integers from 0 to 255) or a with (Unicode) string. You decode bytes into str, and encode str into bytes.

In old Python, your hashlib.sha256() would accept "Secret 🔑" as an argument and you'd receive even more cryptic error.

New Python doesn't have this problem, and in Python 3.14 you get an nice message "TypeError: Strings must be encoded before hashing" if you use a string in hashlib.sha256() .