簡體   English   中英

Raspberry Pi上的Python Idle3中的“無效語法”

[英]“Invalid Syntax” In Python Idle3 on Raspberry Pi

我不知道問題出在哪里,我已經檢查了Geany,Idle甚至直接的Python Shell中的代碼,但是在嘗試將文本打印到控制台時,我一直收到相同的“語法錯誤”。

這是我完整的代碼:

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

如評論中所述,嘗試將其作為功能。 例如,print成為函數而不是語句

teststring = "hello world"
print(teststring)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM