Issue 25620: Bytes Issue - Python tracker (original) (raw)

Issue25620

Created on 2015-11-13 19:16 by Marios Kourtesis, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (3)
msg254613 - (view) Author: Marios Kourtesis (Marios Kourtesis) Date: 2015-11-13 19:16
Hello, Executing the following code in a Python2 interpreter the result is True while running the same code in Python3 is False. I tested this in Python version 2.7.10 and 3.4.2. a = b'a' b = b'b' c = a+b c[1] == b'b' When I call type(c[1]) in Python2 I get str: type(c[1]) <type 'str'> While in Python3 I get int: type(c[1]) <class 'int'> Is this the expected behavior?
msg254614 - (view) Author: SilentGhost (SilentGhost) * (Python triager) Date: 2015-11-13 19:21
Yes. It follows from definition of bytes in python3 https://docs.python.org/3/library/functions.html#bytes Some useful information is also available in 3.0 release notes: https://docs.python.org/3/whatsnew/3.0.html#text-vs-data-instead-of-unicode-vs-8-bit
msg254636 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2015-11-13 23:32
More up-to-date information about the differences might be <https://docs.python.org/3/howto/pyporting.html#text-versus-binary-data>. If you want code that works in both versions, I find it simpler to use slicing: c[1:2] == b'b'.
History
Date User Action Args
2022-04-11 14:58:23 admin set github: 69806
2015-11-13 23:32:25 martin.panter set nosy: + martin.pantermessages: +
2015-11-13 19:21:57 SilentGhost set status: open -> closednosy: + SilentGhostmessages: + resolution: not a bugstage: resolved
2015-11-13 19:16:42 Marios Kourtesis create