Jan-31-2020, 10:14 PM
Can someone please translate this line of code please?
while lines[0].strip()[-3:] != 'YES':
lines is a list of data(strings) returned from the w1_slave file created from a DS18B20 temperature sensor. Below is an example of what is contained within the w1_slave file
8c 01 4b 46 7f ff 04 10 2e : crc=2e YES
8c 01 4b 46 7f ff 04 10 2e t=24750
Here is the method used to create the list of lines from the w1_slave file
# read_temp_raw method to open the w1_slave file, read the lines of data and put them into a list
def read_temp_raw():
f = open(device_file, 'r') #opens the device file, w1_slave, created by the DS18B20
lines = f.readlines() #returns a list of the lines within the w1_slave file
f.close()
return lines
Going back to the original line in question:
while lines[0].strip()[-3:] != 'YES':
I think it may be stripping everything but the last three characters in the line. Is that correct?
while lines[0].strip()[-3:] != 'YES':
lines is a list of data(strings) returned from the w1_slave file created from a DS18B20 temperature sensor. Below is an example of what is contained within the w1_slave file
8c 01 4b 46 7f ff 04 10 2e : crc=2e YES
8c 01 4b 46 7f ff 04 10 2e t=24750
Here is the method used to create the list of lines from the w1_slave file
# read_temp_raw method to open the w1_slave file, read the lines of data and put them into a list
def read_temp_raw():
f = open(device_file, 'r') #opens the device file, w1_slave, created by the DS18B20
lines = f.readlines() #returns a list of the lines within the w1_slave file
f.close()
return lines
Going back to the original line in question:
while lines[0].strip()[-3:] != 'YES':
I think it may be stripping everything but the last three characters in the line. Is that correct?