Hi,
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 [43]: bool(0)
Out[43]: False
In [44]: bool(False)
Out[44]: False
In [45]: bool('')
Out[45]: 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 [46]: bool('0')
Out[46]: True
In [47]: bool('False')
Out[47]: 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[5], type(sline[5]), bool(sline[5])
Results in:
'' <type 'str'> True
Am I going crazy, why doesn't this evaluate to False? bool('') is False....