I'm reading in a list of samples from a text file and in that list every now and then there is a "channel n" checkpoint. The file is terminated with the text eof. The code that works until it hits the eof which it obviously cant cast as a float
log = open("mq_test.txt", 'r')
data = []
for count, sample in enumerate(log):
    if "channel" not in sample:
        data.append(float(sample))
        
print(count)
log.close()
So to get rid of the ValueError: could not convert string to float: 'eof\n' I added an or to my if as so,
log = open("mq_test.txt", 'r')
data = []
for count, sample in enumerate(log):
    if "channel" not in sample or "eof" not in sample:
        data.append(float(sample))
        
print(count)
log.close()
And now I get ValueError: could not convert string to float: 'channel 00\n'
So my solution has been to nest the ifs & that works.
Could somebody explain to me why the or condition failed though?
 
     
    