Trouble with comparison operators in 'if' statements

So I have part of a script I am trying to get to work. If I use equals (==) in the statement and set the value I want to compare to the exact value that gets returned, it triggers as it should. If the result equals the value it runs the following commands, and if it doesn’t it runs the commands under else.

What I am struggling with is trying to use >, <, >=, or <= operator - it doesnt trigger correctly. In the if statement below I am saying if the result is greater than or equal to 14, to do XYZ. However when I run this, even if the return value is less than 14 (lets say 4) its runs the action as if it were true and it doesnt run the ‘else’ actions. Is there a different way to do this? Everything I read online suggests these are accurate comparison operators and should work but for some reason it’s not.


result=process.communicate()
ret=process.returncode
if ret==0:
     <u><b>if result[0].strip() >= '14':</b></u>
          print result[0].strip()
           ...more commands here....
     else:
            ...do something else....

Hi @minntech,

We have asked our script developers to check and provide feedback.

Kind Regards,
PremJK

Hi @minntech,

Our script developers advised to use this
if result[0].strip() >= 14:

As ‘14’ here refere string type.

If you still have any issues, please share with us the complete code in the private message and what exact output you need, so that we can check and update you.

Kind Regards,
PremJK

It still does not work even as the way you stated.
I also tried with double quotes and it doesn’t work either.
Currently on the machine, the result that returns is 5, however its still running the commands as if the statement were true, which it’s not.
I will send you the complete script

Hi @minntech,

We have shared your code with script developers, will check and update you with their input.

Kind Regards,
PremJK

Hi @minntech,

Please check your Inbox for a private message, we have shared a modified custom script, please try that and provide your inputs.
Thanks in advance.

Kind Regards,
PremJK

for anyone that might stumble on this later, it seems the statement needs to be wrapped in int() to define that the result should be an integer…Im just assuming since I dont know much about python.

so it ended up needing to be: if int(result[0].strip()) >= 14: