python 3.x - using split() with subprocess.check_output() -
i'm trying take output of upower -d (shell command) , split long list using .split() can searched.
when do
import subprocess dump = subprocess.check_output(["upower", "-d"]) print(dump.split()) it print output in list form expected except every element in list preceded "b" (not inside string).
when same in python 2.7 gives me output expect in python 3.
b"" bytes literal in python. in python 2.7, "" bytestring. print(your_list) prints representations (repr) of each item why see b"" in python 3 not in python 2.
subprocess.check_output() returns bytes in both python 2 , 3 unless universal_newlines=true specified in python 3 uses locale.getpreferredencoding(false) decode bytes.
from subprocess import check_output output = check_output(["upower", "-d"], universal_newlines=true) print(output.split())
Comments
Post a Comment