Syntax 调用Raspberry Pi temp sensor时,将驱动程序作为bash脚本调用时语法无效
我目前正在为我的树莓皮装一个温度传感器,遇到了这个问题。为了运行代码中指定的驱动程序,我必须运行shell命令。我很难弄明白为什么我的语法不正确 代码: 错误: 添加shell之前出错=TrueSyntax 调用Raspberry Pi temp sensor时,将驱动程序作为bash脚本调用时语法无效,syntax,raspberry-pi,temperature,Syntax,Raspberry Pi,Temperature,我目前正在为我的树莓皮装一个温度传感器,遇到了这个问题。为了运行代码中指定的驱动程序,我必须运行shell命令。我很难弄明白为什么我的语法不正确 代码: 错误: 添加shell之前出错=True 这将修复您的语法错误: def read_dht22( PiPin ): output = subprocess.check_output(["/home/pi/Adafruit-Raspberry-Pi-Python-Code/Adafruit__DHT_Driver", "2302", st
这将修复您的语法错误:
def read_dht22( PiPin ):
output = subprocess.check_output(["/home/pi/Adafruit-Raspberry-Pi-Python-Code/Adafruit__DHT_Driver", "2302", str(PiPin)], shell=True)
sudo python scr6.py
File "scr6.py", line 31
output = subprocess.check_output([shell=True], ['/home/pi/Adafruit-Raspberry-Pi-Python-Code/Adafruit_DHT_Driver', '2302', str(PiPin)])
^
SyntaxError: invalid syntax
sudo python scr5.py
Traceback (most recent call last):
File "scr5.py", line 46, in <module>
temp_c, temp_f = read_dht22(4)
File "scr5.py", line 31, in read_dht22
output = subprocess.check_output(["/home/pi/Adafruit-Raspberry-Pi-Python-Code/Adafruit_DHT_Driver", "2302", str(PiPin)])
File "/usr/lib/python2.7/subprocess.py", line 537, in check_output
process = Popen(stdout=PIPE, *popenargs, **kwargs)
File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1259, in _execute_child
raise child_exception
OSError: [Errno 13] Permission denied
def read_dht22( PiPin ):
output = subprocess.check_output(["/home/pi/Adafruit-Raspberry-Pi-Python-Code/Adafruit__DHT_Driver", "2302", str(PiPin)], shell=True)