The following python returns the CPU temperature of my Raspberry Pi running Raspian 8.0 jessie:
import commands
err, msg = commands.getstatusoutput('vcgencmd measure_temp')
if not err:
print msg
returns "temp=47.2'C"
with a standard single quote instead of the degrees symbol.
This gives me the temperature as a float and so I have something that works.
print float(msg.split('=')[1].split("'")[0])
returns the float 47.2
Question: But I wonder if there is a better, or more pythonic, or at least less hackish-looking way to do this?
note: I don't know how the OS builds the string, but the number could be variable in length, be > 100C or even have a minus sign, or possibly even have the trailing zero suppressed. See https://raspberrypi.stackexchange.com/search?q=+liquid+nitrogen
I have heard of regex but I don't normally do much with strings and have never tried to use it.