3 ms·
IMO, it's a good thing that decode() doesn't on strings in Python 3.
by dagenix 5y ago
IMO, it's a good thing that decode() doesn't on strings in Python 3.
- throwaway81523 5y agoThere is a case to be made either way. The point is that it's yet another quirky difference that pops up sometimes, and using python3 keeps bringing up a stream of such issues. It does seem in the spirit of Python's duck typing to be able to say '616263'.decode('hex') and get 'abc', and that does work fine in py2. Try it in py3 and you get a type error. So ok, convert the string to bytes, e.g. by saying b'616263' instead of '616263'. That doesn't work either, but I'll leave the experiment to you.
- adwn 5y agoSo, like this? codecs.decode(b'616263', 'hex') If that's correct, what's so hard/bad about this?