Best way to iterate through output to get the status of devices - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Best way to iterate through output to get the status of devices (/thread-26128.html) |
Best way to iterate through output to get the status of devices - idkwhatimdoing - Apr-22-2020 I'm using python 2.7.5 I currently using subprocess to run a local command and I'm trying to iterate over a list to get the status of each device. example partial command "status" output: there are about 50 items in the output name: one date: blah status: ok name: two date: blah status: bad partial code: import subprocess, os status = subprocess.Popen('command', 'option1', 'option2', var, stdout=subprocess.PIPE, stderr=subprocess.PIPE) output, err = status.communicate() expected output: one ok two bad etc attempts: I tried using a for line in output statement with multiple if statements for if 'name' and if 'status' while appending them to a list, but i'm not sure if this is the best way. Any thoughts? |