Take the 2-minute tour ×

I have a program which tries to use the output of another script to decide what to do.

I take in the stdout of a Python process from an SSH session, the output of which is either "Verified" or "Unverified", which appears on the command line when I print it as ['Verified\n'].

My code is below. First I read in the output, then print it, then try to compare it. However it always comes out as the second option, that a does not equal verified - even when it should. Perhaps there is something I am missing about stdout, but I have tried many variations of the (if a == ) condition, including with the brackets I listed above. I'm not sure why it doesn't work at all.

stdin, stdout, stderr = ssh.exec_command("python verify.py")

a = stdout.readlines()
print a

if (a == "Verified"):
    print ("a does equal verified")
    print ("a does not equal verified")
share|improve this question
Please.. no parentheses around conditions unless you need them e.g. due to line wrapping. –  ThiefMaster Aug 20 '12 at 21:30

1 Answer 1

up vote 1 down vote accepted

readlines() returns a list and as you pointed out it returns with the \n

Have you tried this?:

if(len(a) and a[0] == "Verified\n"):
  # verfiied, do your stuff here 
share|improve this answer
Use a instead of len(a) and please get rid of the parentheses around the condition. –  ThiefMaster Aug 20 '12 at 21:30
Thank you, this solved my problem first time. –  user1598386 Aug 20 '12 at 23:32

Your Answer


