5
if tarX == 'ini' or 'txt' and act == 'm':

In normal English the if statement needs to verify 2 conditions are true:

  1. that tarX (a variable) is either ini or txt
  2. that act (a variable) is equal to m

I tried several variations to no avail. I'm sure it's my syntax/logic error not python inability. The statement below works because (assumption) the condition to the left of the and statement compares a variable (tarX) for equality of a single string (exe) and the same holds true for the condition on the right variable (act) compared to (m). I'm assuming I'm not correctly "packaging" the if tarX == 'ini' or 'txt' and act == 'm': statement.

if tarX == 'exe' and act == 'm':

Gary Washington
  • 107
  • 1
  • 3
  • 9

1 Answers1

7

Your line needs to be written like this:

if tarX in ('ini', 'txt') and act == 'm':

Remember that a programming language is not English, no matter how closely it resembles it.

  • does the in see tarX as a literal string "tarX" or in its correct context as a variable (which may have ini txt dds or exe as its value)? – Gary Washington Jan 09 '14 at 18:31
  • @GaryWashington - It sees it as a variable. The `in` operator in Python tests for membership. So, the code `tarX in ('ini', 'txt')` is basically saying "can the value of the variable `tarX` be found in the tuple `('ini', 'txt')`. –  Jan 09 '14 at 18:35