Raspberry Pi数字接口python错误

Raspberry Pi数字接口python错误,python,python-3.x,raspberry-pi,new-operator,Python,Python 3.x,Raspberry Pi,New Operator,我为我的Raspberry pi创建了一个python脚本。它与插入pi的GPIO引脚的数字接口连接。虽然当我运行pi时,我在下面得到了这个错误。虽然当我在代码末尾加上“”,它会运行,但不会输出任何东西。我对此感到非常困惑?我对脚本编写也很陌生 File "door_controller.py", line 48 ^ SyntaxError: EOF while scanning triple-quoted string literal #!/usr/bin/env python """

我为我的Raspberry pi创建了一个python脚本。它与插入pi的GPIO引脚的数字接口连接。虽然当我运行pi时,我在下面得到了这个错误。虽然当我在代码末尾加上“”,它会运行,但不会输出任何东西。我对此感到非常困惑?我对脚本编写也很陌生

File "door_controller.py", line 48

^
SyntaxError: EOF while scanning triple-quoted string literal


 #!/usr/bin/env python
"""Door Lock: System to control an electric lock

import piface.pfio as piface
from time import sleep

class DoorControllerPiFace:
    def send_open_pulse(self):
        piface.digital_write(0,1)
        sleep(5)
        piface.digital_write(0,0)

class AuthToken:
    def _init_(self, id, secret):
        self.id=id
        self.secret.secret

class TestDoorController:
    def send_open_pulse(self):
        print "unlock the door"

class BasicAuthenticator:
    id = "Andrew"
    secretPassword = "1234"
    def check(self,token):
        print "checking input of '" + token.id "',password: " + token.secret + ", against secret password'" + self.secretPassword +"'"
            result = (token.secret == self.secretPassword) & (token.id == self.id)
            print "authentication is: " + str(result)
            return result

class TestInput
    def getInput(self):
        print "checking for input"
        authToken + AuthToken("Andrew","1234")
        return authInput

def main():
    authInput = TestInput()
    authenticator = BasicAuthenticator()
        doorController = DoorControllerPiFace()

if(authenticator.check(authInput.getInput())):
    doorController.send_open_pulse()
if _name_ == '_main_':

    main()
python
import piface.pfio
piface.pfio.init()
piface.pfio.digital_write(0, 1)
led0 = piface.pfio.LED(0)
led0.turn_off()
在我修复了一些小错误并更正了一些空格和缩进之后。我在第42行收到一个错误,说我的验证器没有定义。但是我确定我已经用上面的BasicAuthenticator类定义了它

#!/usr/bin/env python3
"""Door Lock: System to control an electric lock"""

import piface.pfio as piface
from time import sleep

class DoorControllerPiFace:
    def send_open_pulse(self):
        piface.digital_write(0,1)
        sleep(5)
        piface.digital_write(0,0)

class AuthToken:
    def _init_(self, id, secret):
        self.id=id
        self.secret.secret

class TestDoorController:
    def send_open_pulse(self):
        print "unlock the door"

class BasicAuthenticator:
    id = "Andrew"
    secretPassword = "1234"
    def check(self,token):
        print "checking input of '" + token.id + "', + password + : " + token.secret + ", against secret password'" + self.secretPassword +"'"
        result = (token.secret == self.secretPassword) & (token.id == self.id)
        print "authentication is: " + str(result)
        return result

class TestInput:
    def getInput(self):
        print "checking for input"
        authToken + AuthToken("Andrew","1234")
        return authInput

def main():
    authInput = TestInput()
    authenticator = BasicAuthenticator()
    doorController = DoorControllerPiFace()

if(authenticator.check(authInput.getInput())):
   doorController.send_open_pulse()
if _name_ == '_main_':

    main()
python
import piface.pfio
piface.pfio.init()
piface.pfio.digital_write(0, 1)
led0 = piface.pfio.LED(0)
led0.turn_off()
修复了我的if语句缩进不正确的问题 没关系,现在脚本运行了,但什么也没发生。没有错误,它只是运行并重新启动。它应该能够打开一个机电锁5秒钟。我手动运行python,我可以使用

python
import piface.pfio
piface.pfio.init()
piface.pfio.digital_write(0, 1)
led0 = piface.pfio.LED(0)
led0.turn_off()

然后,当我运行脚本时,什么也没有发生?我知道这是在我的DoorController类中定义的,但它似乎在运行

您在模块的开头有一个docstring,但它从未终止,因此Python抱怨。
python
import piface.pfio
piface.pfio.init()
piface.pfio.digital_write(0, 1)
led0 = piface.pfio.LED(0)
led0.turn_off()
请确保在以下情况下终止它:

python
import piface.pfio
piface.pfio.init()
piface.pfio.digital_write(0, 1)
led0 = piface.pfio.LED(0)
led0.turn_off()
"""Door Lock: System to control an electric lock"""

这是我的问题,尽管我不知道应该在哪里结束它。我尝试在任何地方结束它都会导致代码运行,但什么都没有发生?如果我听起来很傻,那很抱歉,我只是对python非常陌生。@user3211153:docstring只是嵌入到代码其余部分中的一小段文档。当你不再看到英文散文和如果看到代码,您可能应该结束docstring。在您的特定情况下,我会将结尾
放在开始它的行的末尾,如我在回答中所示。您的右侧:)。我刚刚写了一个小时,所以我有点失望。虽然现在我在第26行的“+token.secret+”@user3211153”中出错:你在
token.id
”之间缺少一个
++
,密码: