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 splitlines() method returns strings without decoding
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.6, Python 3.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: paul.moore, socketpair, wolma, zach.ware
Priority: normal Keywords:

Created on 2016-03-07 10:26 by paul.moore, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (8)
msg261289 - (view) Author: Paul Moore (paul.moore) * (Python committer) Date: 2016-03-07 10:26
See the following test (in Python 3.5):

>>> u'a\nb£'.encode('utf-8').splitlines()
['a', 'b\xc2\xa3']

I encode a string in UTF-8, then use the (bytes) splitlines function on it. The return value is a list of strings, containing encoded byte values.

The bytes object isn't even documented as having a splitlines method - and if it does, then it should be returning a list of bytes objects.
msg261292 - (view) Author: Марк Коренберг (socketpair) * Date: 2016-03-07 10:49
No, I have checked, it returns list of `bytes` objects.
msg261293 - (view) Author: Марк Коренберг (socketpair) * Date: 2016-03-07 10:50
$ python3.5
Python 3.5.0+ (default, Oct 11 2015, 09:05:38) 
[GCC 5.2.1 20151010] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> u'a\nb£'.encode('utf-8').splitlines()
[b'a', b'b\xc2\xa3']
msg261298 - (view) Author: Wolfgang Maier (wolma) * Date: 2016-03-07 12:52
works for me too on Windows:

Python 3.5.1 (v3.5.1:37a07cee5969, Dec  6 2015, 01:38:48) [MSC v.1900 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> u'a\nb£'.encode('utf-8').splitlines()
[b'a', b'b\xc2\xa3']
msg261299 - (view) Author: Wolfgang Maier (wolma) * Date: 2016-03-07 12:54
oh and documentation is here:
https://docs.python.org/3.5/library/stdtypes.html?highlight=bytes.splitlines#bytes.splitlines
msg261311 - (view) Author: Zachary Ware (zach.ware) * (Python committer) Date: 2016-03-07 17:56
Paul, I think you were in a Python 2 session:

$ python
Python 2.7.10 (v2.7.10:15c95b7d81dc, May 23 2015, 09:33:12) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> u'a\nb£'.encode('utf-8').splitlines()
['a', 'b\xc2\xa3']
>>> ^D
$ python3
Python 3.5.1 (v3.5.1:37a07cee5969, Dec  5 2015, 21:12:44) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> u'a\nb£'.encode('utf-8').splitlines()
[b'a', b'b\xc2\xa3']
>>>
msg261316 - (view) Author: Paul Moore (paul.moore) * (Python committer) Date: 2016-03-07 22:38
That's weird. I can confirm it's working for me on 3.5.1. I'll double check I wan't in 2.7 when I'm back at my work PC, but I didn't *think* I was. But regardless, there's clearly no bug here.

Apologies for the confusion.
msg261335 - (view) Author: Paul Moore (paul.moore) * (Python committer) Date: 2016-03-08 09:00
Sigh. I had installed Python 2.7 at some point, and py.exe picked it up by default :-(

Isn't it about time that py.exe defaulted to the latest version installed, not the latest version of Python 2?
History
Date User Action Args
2022-04-11 14:58:28adminsetgithub: 70688
2016-03-08 09:00:59paul.mooresetmessages: + msg261335
2016-03-07 22:38:06paul.mooresetmessages: + msg261316
2016-03-07 17:56:55zach.waresetstatus: open -> closed

type: behavior

nosy: + zach.ware
messages: + msg261311
resolution: not a bug
stage: resolved
2016-03-07 12:54:28wolmasetmessages: + msg261299
2016-03-07 12:52:29wolmasetnosy: + wolma
messages: + msg261298
2016-03-07 10:50:05socketpairsetmessages: + msg261293
2016-03-07 10:49:22socketpairsetnosy: + socketpair
messages: + msg261292
2016-03-07 10:26:20paul.moorecreate