[solved] if output=='none' does not work

Posted on
Thu May 21, 2020 3:56 am
Nine offline
Posts: 78
Joined: Feb 15, 2015
Location: Zurich, Switzerland

[solved] if output=='none' does not work

I use a little python script to get the status of my sureflap:

Code: Select all
import subprocess
cmd = "php /Users/simon/sureflap_ohne_output/getLockMode.php"
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
output = p.stdout.read()

# Save status in a variable
indigo.variable.updateValue("sureflap", output)

# Write status to log
indigo.server.log(output, "Status sureflap")

if output=="none":
   indigo.server.log("Status is none --> do other things...")

Even the status is correctly written to the log as "none" or "out" (without quotationmarks), the
if output=="none":
does not work. Nothin happens :?

Simon
Last edited by Nine on Thu May 21, 2020 5:05 am, edited 1 time in total.

Posted on
Thu May 21, 2020 5:00 am
neilk offline
Posts: 714
Joined: Jul 13, 2015
Location: Reading, UK

Re: if output=='none' does not work

Simon,
No expert but it could be that you have some hidden trailing or leading characters.

https://stackoverflow.com/questions/21667511/string-comparison-fails

A few other options to strip out hidden characters.

Thanks,
Neil

Posted on
Thu May 21, 2020 5:04 am
Nine offline
Posts: 78
Joined: Feb 15, 2015
Location: Zurich, Switzerland

Re: if output=='none' does not work

Thanks Neil!

I added
Code: Select all
output = output.strip()
and now it works :lol:

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 3 guests