lundi 8 novembre 2021

Find two occurences in the same line

I have the output of a command, something like this:

machine: alias_machine: status Idle - true -
machine2: alias2: status Idle - true    -
machine3: alias3: status Idle - false    -
machine4: alias4: status Charging - False    -

I have to search if, in one of those machines, the status is Idle and False (at the same time).

To do that, I use this:

if output.find("Idle") and output.find("false"):
    print ("Blablah")

But the problem is, that "Idle" and "false" could be found in other lines, so this does not do the trick.

I also tried this, and it works:

if output.find("Idle - false"):
    print ("Blablah")

But there is a problem, if there is an update in the software or something and the output changes (whitespaces, breaklines, tab, etc), I would have to rewrite the code again...

If I transform it into a list, the format is going to be changed... So I could not use the result later...

Aucun commentaire:

Enregistrer un commentaire