yes, i am an author of this Change conditions using loop and array in python
So, i am trying to change conditions from this:
if sys.argv[1] == 'add':
sys.exit(add(db, usr))
if sys.argv[1] == 'rem':
sys.exit(rem(db, usr))
if sys.argv[1] == 'rmusr':
sys.exit(rmusr(db, usr))
I am trying to change these conditions at list with loop
From answers of other developers, i used this:
actions = ['add','rem','rmusr']
if sys.argv[1] in actions:
sys.exit(sys.argv[1](db, usr))
But, when i am trying to check it function, i have this
File "sql.py", line 25, in <module>
sys.exit(sys.argv[1](db, usr))
TypeError: 'str' object is not callable
I can't understand, where i have an error ?
sys.argv[1](db, usr), you're actually literally doing this:"rem"(db, usr). The solution is to change the array of strings to an array of functions