I have a function to collect temperature (values from text files) which uses a partly predefined path. However, sometimes the path does not exist if the temperature sensor wasn't loaded (is disconnected). How can I set a condition or exception to skip a loop if a path is not available?
I wanted to use continue, but i have no idea what condition to set with it.
def read_all():
base_dir = '/sys/bus/w1/devices/'
sensors=['28-000006dcc43f', '28-000006de2bd7', '28-000006dc7ea9', '28-000006dd9d1f','28-000006de2bd8']
for sensor in sensors:
device_folder = glob.glob(base_dir + sensor)[0]
device_file = device_folder + '/w1_slave'
def read_temp_raw():
catdata = subprocess.Popen(['cat',device_file], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out,err = catdata.communicate()
out_decode = out.decode('utf-8')
lines = out_decode.split('\n')
return lines