Вопрос

I created a python script for my Raspberry pi. It interfaces with a digital interface that plugs into the pi's GPIO pins. Though when i run the pi I get this error below. Though when i add """ to the end of the code it runs but wont output anything. Im very puzzled by this? Im also very new to scripting.

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()

Ok so after I fixed some minor errors and corrected some spacing and indentation. Im receiving an error on line 42 say that my authenticator is not defined. But I sure that I have it defined with my BasicAuthenticator class above?

#!/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()

Fixed the problem my if statements where not indented correctly Never mind, now the script runs but nothing happeneds. There is no errors it just runs and restarts. Its supposed to be able to open a electromachanical lock for 5secs. Ive run python manually and I can get the lock to open using

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

Then when I run the script nothing happens? I know this is defined in my DoorController Class but its dosnt seem to run

Это было полезно?

Решение

You have a docstring at the start of your module, but it's never terminated, so Python complains.
Make sure you terminate it:

"""Door Lock: System to control an electric lock"""
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top