当运行下面的代码时,我得到一个缩进错误,但我似乎无法找到问题。我是python的新手,所以我敢肯定它显然很明显,但我看不到它。RaspberryPi Python IndentationError:预计有一个缩进块
#Import modules to send commands to GPIO pins
from subprocess import call
import RPi.GPIO as gpio
import time
#Define function to keep script running
def loop():
while True:
time.sleep(0.2)
#Define function to run when interrupt is called
def shutdown(pin):
call('halt', shell=False)
GPIO.setmode(GPIO.BOARD) #Set pin numbering to board numbering
GPIO.setup(7, GPIO.IN) #Set pint 7 as input pin
GPIO.add_event_detect(7. GPIO.RISING, callback=shutdown, bouncetime=200) #Setup inteript to look button press
loop()
在运行时我得到这个错误:
File "/home/pi/PiSupply/softshut.py", line 8
while True:
^
IndentationError: expected an indented block
请帮帮忙,我已经花了太长时间就这个问题和我似乎无法找到它的指压痕错误。
在此先感谢。
根据[能够找到的所有在线示例](https://docs.python.org/2/tutorial/controlflow.html#defining-functions),整个函数体必须缩进。你究竟在哪里找到构造函数,函数体没有缩进? –
你发布的错误回答你的问题... – coder