You stop using Python 2(dead💀),that you use Raspberry Pi is no excuse as most of there stuff is updated.
So in Python 3.9,see that Unicode can now be used in string one biggest update moving from 2 to 3.
So in Python 3.9,see that Unicode can now be used in string one biggest update moving from 2 to 3.
>>> temp = 24.5 >>> print(f"temperature {temp}°C)") temperature 24.5°C)
import re, subprocess def check_CPU_temp(): temp = None err, msg = subprocess.getstatusoutput('vcgencmd measure_temp') if not err: m = re.search(r'-?\d\.?\d*', msg) # a solution with a regex try: temp = float(m.group()) except ValueError: # catch only error needed pass return temp, msg temp, msg = check_CPU_temp() print(f"temperature {temp}°C") print(f"full message {msg}")