NameError:名称"true"未定义
问题描述:
我有以下代码,并在尝试运行它时收到以下错误消息:
I have the following code and get the following error message when trying to run it:
NameError: name 'true' is not defined
我试图让Raspberry Pi在端口17上收到输入时运行HTML脚本:
I am trying to make the Raspberry Pi run a HTML script when it receives input on port 17:
import RPi.GPIO as GPIO
import time
import os
inputSignal = 17
GPIO.setmode(GPIO.BCM)
GPIO.setup(inputSignal,GPIO.IN)
while true:
if (GPIO.input(inputSignal)):
os.system("html /home/pi/index.html")
else:
print("No Input")
答
Python的布尔常量大写: True
和 False
分别使用大写字母T
和F
.
Python’s boolean constants are capitalized: True
and False
with upper case T
and F
respectively.
小写变体只是变量的有效免费名称,因此您可以将它们用于任何所需的变量,例如true = False
(不推荐; P).
The lower-case variants are just valid free names for variables, so you could use them for whatever you want, e.g. true = False
(not recommended ;P).