NameError:名称"true"未定义 [英] NameError: name 'true' is not defined

查看:226
本文介绍了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 分别使用大写字母TF.

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

这篇关于NameError:名称"true"未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆