1

I'm trying to check a line of output from my code, to see if it contains "Active: Exited" or "Active: Inactive".

I've tried to use: if "Active: Exited" or "Active; Inactive" in output: but this just triggers no matter what is in the output.

If I just say: if "Active: Exited" in output: it works as it's supposed to.

Mert Köklü
  • 2,183
  • 2
  • 16
  • 20
Toftegaard
  • 55
  • 1
  • 7

1 Answers1

2

Python's in test does not distribute. What you're trying to say is

if ("Active: Exited" or "Active; Inactive") in output:

but Python interprets this as

if ("Active: Exited") or ("Active; Inactive" in output):

in which case the string "Active: Excited" is so-called 'truthy', so your or always evaluates to True.

What you want is this:

if "Active: Exited" in output or "Active; Inactive" in output:
# AKA
# if ("Active: Exited" in output) or ("Active; Inactive" in output): 
Energya
  • 2,623
  • 2
  • 19
  • 24