0
if 'PASSED' in cell.value or 'FAILED' in cell.value or 'INVALID' in cell.value:
    Test.append(6)

What is a more concise way to do this? I want to make it do something like

if cell.value in ('PASSED','INVALID', 'FAILED')

but that doesn't work

10
  • possible duplicate of How to check if one of the following items is in a list? Commented Jul 24, 2015 at 18:57
  • Why does this 'hello' in ( 'hello', 'world' ) #returns True not work for you? Are you sure that cell.value is a string ? Commented Jul 24, 2015 at 18:58
  • 1
    If cell.value is a string then "if cell.value in ('PASSED','INVALID', 'FAILED'):" will absolutely work - what error did you get? Commented Jul 24, 2015 at 19:03
  • @dermen: clearly cell.value is a larger string which may contain any of those three strings. Commented Jul 24, 2015 at 21:02
  • @gkusner: that'll only work if cell.value is exactly one of those strings, but not if cell.value contains such a string; e.g. cell.value is a longer string like "The tests results were INVALID". 'INVALID' in cell.value is then true, but your test is not. Commented Jul 24, 2015 at 21:04

1 Answer 1

3

Use the any() function and a generator expression:

if any(s in cell.value for s in ('PASSED','INVALID', 'FAILED')):

This tests each string in turn, returning True as soon as a test passes.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.