This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Bytes Issue
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.4
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Marios Kourtesis, SilentGhost, martin.panter
Priority: normal Keywords:

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:23adminsetgithub: 69806
2015-11-13 23:32:25martin.pantersetnosy: + martin.panter
messages: + msg254636
2015-11-13 19:21:57SilentGhostsetstatus: open -> closed

nosy: + SilentGhost
messages: + msg254614

resolution: not a bug
stage: resolved
2015-11-13 19:16:42Marios Kourtesiscreate