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()

Recommended Answers

All 5 Replies

There is no real difference:

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

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'

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'

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.

Thank you very much! It runs smooth now!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.