![]() |
question on syntax - 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: question on syntax (/thread-22037.html) |
question on syntax - ebolisa - Oct-25-2019 Hi, the code below should return UP but it returns DOWN and I cannot understand why. any help is appreciated. TIA from __future__ import print_function import subprocess _cmd = 'grep RUNNING /proc/asound/card*/pcm*/sub*/status' cmd = 'cat /proc/asound/card*/pcm*/sub*/status | grep state:' p = subprocess.check_output(cmd,shell=True).decode("utf-8") print(p) #prints state: RUNNING if (p=='state: RUNNING'): print('UP') else: print('DOWN') Nevermind. I had white spaces in line. RE: question on syntax - Larz60+ - Oct-26-2019 p may have a line feed, try if p.strip() == 'state: RUNNING':
|