I'm having some difficulty reading in boolean values from a file, particularly false values. Python can understand false values as empty strings, as well as a few other ways. For example:
In : bool(0) Out: False In : bool(False) Out: False In : bool('') Out: False
The problem is, anything I read in from a file is read in as a string. So if a file has these values, all the booleans will evaluate to true. For example:
In : bool('0') Out: True In : bool('False') Out: True
Therefore, in my file, I chose to use empty strings to denote false values in my file. However, when I read these in and try to convert them, they yield TRUE! Here's an example of my data:
5450 0.0 Infinity 0.0 1.0 '' '' f=open('params.txt', 'r') for line in f: sline=line.strip().split() print sline, type(sline), bool(sline)
'' <type 'str'> True
Am I going crazy, why doesn't this evaluate to False? bool('') is False....