質問

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