I am writing a small Python interface for reading temperatures from a DS18B20 sensor via sysfs. In addition to temperature, you can also read the state of the CRC sum. To trigger a CRC error, I decided to use IOError:
sn = "28-000005589697"
fname = "sys/bus/w1/devices/" + sn + "/w1_slave"
with open(fname, 'f') as f:
...
raise IOError("Invalid CRC in {}!".format(sn))
As I understand it IOError, it has members message, filename, errnoand strerror. In my approach it is used only message. It seems that I missed something.
What is the best practice for throwing an exception IOError, so it goes well with other errors like full disk or file not found, etc.?
source
share