문제

I want to run this command from python

/opt/vc/bin/vcgencmd measure_temp

when I run it in python it prints the temperature to the screen and returns 0. When I try to assign it to a variable it assigns 0 too.

>>> import os
>>> os.system('/opt/vc/bin/vcgencmd measure_temp')
temp=42.8'C
0
>>> temp=os.system('/opt/vc/bin/vcgencmd measure_temp')
temp=42.8'C
>>> temp
0
>>>

How can I run this command in python and assign the actual temperature to a variable?

도움이 되었습니까?

해결책

os.system doesn't returns the output, use subprocess.check_output for that.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top