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: print() from pipe enclosed between {b'} and {'}-pair on python3
Type: behavior Stage:
Components: Interpreter Core Versions: Python 3.1
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: amaury.forgeotdarc, ricardw
Priority: normal Keywords:

Created on 2011-01-18 11:12 by ricardw, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (2)
msg126457 - (view) Author: (ricardw) Date: 2011-01-18 11:12
The following script produces different output on python2.6.6 vs. python3.1.2:
-------------
import subprocess, sys

ls = subprocess.Popen(['ls', '-l', '/etc/motd'], stdout=subprocess.PIPE,)

end_of_pipe = ls.stdout

print('Result:')

for line in end_of_pipe:
    print(line.strip())
-------------

Result from invoking with python2 and python3 are respectively:

Result:
-rw-rw---- 1 root root 25 Jan 18 10:25 /etc/motd

and:

Result:
b'-rw-rw---- 1 root root 25 Jan 18 10:25 /etc/motd'

Is this difference a feature, or a bug ?
msg126462 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2011-01-18 13:19
It's a feature. Subprocess output is binary data, not text; and since python3, the string type is now what python2 called unicode!

Please read http://docs.python.org/py3k/whatsnew/3.0.html#text-vs-data-instead-of-unicode-vs-8-bit
for an explanation of the most important difference between python2 and python3.
History
Date User Action Args
2022-04-11 14:57:11adminsetgithub: 55140
2011-01-18 13:19:32amaury.forgeotdarcsetstatus: open -> closed

nosy: + amaury.forgeotdarc
messages: + msg126462

resolution: not a bug
2011-01-18 13:01:13ricardwsettitle: print() from pipe enclosed between b' and ' pair on python3 -> print() from pipe enclosed between {b'} and {'}-pair on python3
2011-01-18 13:00:23ricardwsettitle: print() from pipe enclosed between b' and 'pair on python3 -> print() from pipe enclosed between b' and ' pair on python3
2011-01-18 12:59:40ricardwsettitle: print() from pipe enclosed between 'b and 'pair on python3 -> print() from pipe enclosed between b' and 'pair on python3
2011-01-18 11:12:59ricardwcreate