Python NameError: 名称 'true' 未定义
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30095032/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
NameError: name 'true' is not defined
提问by Jesper Andersen
I have the following code and get the following error message when trying to run it:
我有以下代码并在尝试运行它时收到以下错误消息:
NameError: name 'true' is not defined
I am trying to make the Raspberry Pi run a HTML script when it receives input on port 17:
我试图让 Raspberry Pi 在端口 17 上接收输入时运行 HTML 脚本:
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")
采纳答案by poke
Python's boolean constants are capitalized: True
and False
with upper case T
and F
respectively.
Python的布尔常量是大写的:True
与False
以大写字母T
和F
分别。
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).
小写变体只是变量的有效自由名称,因此您可以根据需要使用它们,例如true = False
(不推荐;P)。
回答by phihag
You haven't defined a variable true
. Maybe you meant the built-in boolean value True
?
您尚未定义变量true
。也许你的意思是内置的布尔值True
?
回答by Тэм??лэн Содном
while True:
为真:
# but seems like inifite loop
# 但似乎是无限循环