30 | | A more subtle and confusing way to trigger this error is when trying to ''encode'' a sequence of bytes to a given encoding. Wait... encoding a sequence of bytes? Does that make sense? Well, no, normally it shouldn't, but Python "offers" you the `encode` method on `str` objects, as a shortcut to: `"string".encode() == unicode("string").encode()`. That could be called a `u"cadeau empoisonné"` ;-) |
| 30 | A more subtle and confusing way to trigger this error is when trying to ''encode'' a sequence of bytes to a given encoding. Wait... encoding a sequence of bytes? Does that even make sense? Well, normally not, but Python interprets that as a shortcut for encoding the `unicode` object corresponding to this string. So we have the following equivalence: |
| 31 | {{{ |
| 32 | "string".encode(enc) == unicode("string").encode(enc) |
| 33 | }}} |
| 34 | That could be called a `u"cadeau empoisonné"` ;-) |