News for hackers. Stuff that matters.
Re:The Magic 0xC2 by greenshackle2 on Tuesday April 11, 2017 @04:50PM (#14092307)
Yeah especially in Python 2 you can get into fun messes if you don't really understand what you're doing. Python 2 lets you encode bytes:

>>> 'abcd'.encode('ascii')

'abcd'

And decode unicode:

>>> u'abcd'.decode("ascii")

u'abcd'

It's nonsensical.

Thankfully Python 3 has removed all this madness:

>>> b'abcd'.encode('ascii')

AttributeError: 'bytes' object has no attribute 'encode'

>>> 'abcd'.decode('ascii')

AttributeError: 'str' object has no attribute 'decode'

(For those not familiar, Python 3 switched around the notation for unicode/bytes. In Python 2 "abcd" is a bytes literal, adding u makes it unicode, in Python 3 "abcd" is a unicode literal, adding b makes it bytes.)

There are no comments on this comment yet.