Conversation
Notices
-
Claes Wallin (韋嘉誠) (clackemovedtoheldscalla@quitter.se)'s status on Thursday, 20-Oct-2016 12:50:47 UTC Claes Wallin (韋嘉誠) #TIL
$ python2 -c "print(u'asdf' == b'asdf')"
True-
Claes Wallin (韋嘉誠) (clackemovedtoheldscalla@quitter.se)'s status on Thursday, 20-Oct-2016 12:52:51 UTC Claes Wallin (韋嘉誠) Even worse:
$ python2 -c "print({b'asdf': 'qwer'}[u'asdf'])"
qwer -
馬鹿野狐(ばかやこ)✔ (takeshitakenji@gs.kawa-kun.com)'s status on Thursday, 20-Oct-2016 12:56:21 UTC 馬鹿野狐(ばかやこ)✔ @clacke I think you might be missing something:
>>> type(b'123')
<type 'str'>
In Python 2, the 'b' sigil doesn't really do anything. Also, u'123' will equal '123'.Claes Wallin (韋嘉誠) repeated this. -
Claes Wallin (韋嘉誠) (clackemovedtoheldscalla@quitter.se)'s status on Thursday, 20-Oct-2016 12:58:40 UTC Claes Wallin (韋嘉誠) @takeshitakenji Not missing anything, just expression myself clearly for the benefit of non-bilinguals. :-) -
Claes Wallin (韋嘉誠) (clackemovedtoheldscalla@quitter.se)'s status on Thursday, 20-Oct-2016 12:59:46 UTC Claes Wallin (韋嘉誠) @takeshitakenji The real problem is that two values of different type are being coerced for an equality comparison. This is not Javascript. -
馬鹿野狐(ばかやこ)✔ (takeshitakenji@gs.kawa-kun.com)'s status on Thursday, 20-Oct-2016 13:03:17 UTC 馬鹿野狐(ばかやこ)✔ @clacke The real problem is that Python 2 had two 'normal' string types, which is only for compatibility with older Python 2 scripts.
Python 3 has only one 'normal' string type, which is what really solves the problem.Claes Wallin (韋嘉誠) repeated this. -
Claes Wallin (韋嘉誠) (clackemovedtoheldscalla@quitter.se)'s status on Thursday, 20-Oct-2016 14:17:12 UTC Claes Wallin (韋嘉誠) @takeshitakenji I just haven't been this much exposed to Python 2 before, and was surprised by this workaround. I'm glad Python 3 happened.
-