I tried running this piece of code:
path = '/bla/bla/bla' if path is True: print "True" else: print "False"
And it prints False. I thought Python treats anything with value as True. Why is this happening?
In the context of Boolean operations, and also when expressions are used by control flow statements, the following values are interpreted as false: False, None, numeric zero of all types, and empty strings and containers (including strings, tuples, lists, dictionaries, sets and frozensets). All other values are interpreted as true.
The key phrasing here that I think you are misunderstanding is "interpreted as false" or "interpreted as true". This does not mean that any of those values are identical to True or False, or even equal to True or False.
'/bla/bla/bla' will be treated as true where a Boolean expression is expected (like in an
if statement), but the expressions
'/bla/bla/bla' is True and
'/bla/bla/bla' == True will evaluate to False for the reasons in Ignacio's answer.
is compares identity. A string will never be identical to a not-string.
== is equality. But a string will never be equal to either
You want neither.
path = '/bla/bla/bla' if path: print "True" else: print "False"