I have this class:
class test(object):
def __init__(self, s):
self.s = s
def getS(self):
return self.s
I need to generate 5 instances of this class and only 1 instance will have a variable s with a value equal to true.
tests = [test(True) if i==sys.argv[1] else test(False) for i in range(5)]
Then I tried to print the values.
for i in tests:
print i.getS()
Output is:
False
False
False
False
False
Shouldn't one of the value equals to True?
sys.argvis a list of strings, neither of its elements will ever be an integer. (Unless you manually modify it of course.) Tryif i == int(sys.argv[1]).