简体   繁体   中英

“Invalid Syntax” In Python Idle3 on Raspberry Pi

I have no idea what the problem is, I've checked the code in Geany, Idle, and even the straight Python Shell, but I keep getting the same "Syntax Error" when trying to print text to the console.

Heres my complete code:

import RPi.GPIO as GPIO
import time

on = "On"
off = "Off"

GPIO.setmode(GPIO.BCM)

relay = 17

GPIO.setup(relay, GPIO.OUT)

for x in range(0, 3):
    GPIO.output(relay, 1)
    print on # Where Im getting the error. I even tried 'print "on"' but still with errors
    time.sleep(4)
    GPIO.output(relay, 0)
    print off
    time.sleep(4)

GPIO.cleanup()

As mentioned in the comments try it as a function. print became a function instead of a statement for example

teststring = "hello world"
print(teststring)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM