My script runs the C program digitemp. The output is in rows containing the sensor ID and the temperature. I need to match the sensor ID with a particular name thus all the elifs. I have used first, second third in this example as the names to math the ID's. Is there any way to reduce all the elif statements as there are more to be added?
import os
# get digitemps output
cmd = "/bin/digitemp_ -c /bin/digitemp.conf -q -a"
def digitemps():
for outline in os.popen(cmd).readlines():
outline = outline[:-1].split()
if outline[0] == '28F4F525030000D1':
temp_ = outline[1]
print 'first ' + temp_
elif outline[0] == '28622A260300006B':
temp_ = outline[1]
print 'second ' + temp_
elif outline[0] == '28622A2603000080':
temp_ = outline[1]
print 'third ' + temp_
digitemps()