Hi I have a list of False and True, which I have written to a file. When I read the file, I cant get back to my True and False list.... I only get the ["True","False"] version of it, but I want it to be like this: [True,False]
Is it possible to convert it? I have tried bool, it doesnt work..

This is my Read method.

readfromfile = open(tname,"r")
readfromtemp = open(tfname,"r")
read1 = readfromfile.read()
read2 = readfromtemp.read()
self._list = [int(n) for n in read1.split(',')]
self._cord = [n for n in read2.split(',')]
readfromfile.close()
readfromtemp.close()

Edited 6 Years Ago by ekkanh: n/a

There is no real difference:

if condition == True:
if condition == "True":

Edited 6 Years Ago by woooee: n/a

How about:

readfromfile = open(tname,"r")
readfromtemp = open(tfname,"r")
read1 = readfromfile.read()
read2 = readfromtemp.read()
self._list = [int(n) for n in read1.split(',')]
self._cord = [n != 'False' for n in read2.split(',')]
readfromfile.close()
readfromtemp.close()

woooee:

But not with 'False' used without ==

condition = 'False'
if condition:
    print 'Condition True'
else:
    print 'Condition False'

Edited 6 Years Ago by pyTony: n/a

I don't understand your point, unless it is to shorten the number of keystrokes for some reason.

condition = 'False'
if condition == 'True':
    print 'Condition True'
else:
    print 'Condition False'

Edited 6 Years Ago by woooee: n/a

usually it is prefered style not to use == and if the same statements must work before and after saving, you should use

if condition in (False, 'False'):
    do_stuff
else:
   true_stuff

That is prone to mistakes.

This question has already been answered. Start a new discussion instead.