(Sep-14-2018, 12:27 PM)tony1812 Wrote: Thanks for the reply.
I found the second way is better, nice and succinct. And yes it ought to be the same format. Hopefully the cpu temp never reaches temp=123.4 'C :}
In the first method match.group(), some how python complains that in <module>
match.group()
AttributeError: 'NoneType' object has no attribute 'group'
Probably, occasionally you get a string with an integer temp value - changing RE to
r'\d+(\.\d+)?'
will solve that. (and you will be protected even against 123.4 'C )PS I would suggest using
subprocess.check_output
instead of subprocess.popen.readline()
. Of course, in that case RE method is preferred.
Test everything in a Python shell (iPython, Azure Notebook, etc.)
- Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
- Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
- You posted a claim that something you did not test works? Be prepared to eat your hat.