Reputation: 105
I have below code in python and I do not know why but it does not work as expected.
The value from variable isactive is qual to "True" and it is coming from a json dictionary. However, when I write down below if statement, the program is printing "Hola" out. Please see below code:
response = requests.request("GET", url, headers=headers, params=querystring)
variable = response.text
variable = json.loads(variable)
isactive = lista1[listanumber]['IsActive']
print isactive (ourput for this is giving me "True")
if isactive != "True":
print "hola"
However, above if-statement is printing "Hola" and I do not understand why since the isactive variable is equal to "True".
Do you know what may be the problem?
Thanks
Upvotes: 0
Views: 685
Reputation: 541
isactive == True and isactive != 'True'
Test against:
if isactive != True:
print 'hola'
Upvotes: 0
Reputation: 166
A true in json is converted to python True. boolean, not string.
In your comparison, you can then simply type if not isActive:
Upvotes: 1