Python parsing subprocess.check_output ()

I am trying to use and process the output from subprocess.check_output () in python, but since it is being returned by byte

for line in output: # Do stuff 

Does not work. Is there a way that I can restore the output to the formatting of the string that it has when it prints to stdout? Or what is the best way to find and use this output?

Thanks in advance!

+5
source share
1 answer

subprocess.check_output() returns a single row . Use the str.splitlines() method to str.splitlines() over individual lines in this line:

 for line in output.splitlines(): 
+7
source

Source: https://habr.com/ru/post/1214613/


All Articles