NameError: name 'true' is not defined

Question:

I want to use Boolean ( true / false ) in my python source file, but after running the application, I receive the following error:

NameError: name 'true' is not defined

The error lies on while true:, when 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")
Asked By: Jesper Andersen

||

Answers:

Python’s boolean constants are capitalized: True and False with upper case T and F respectively.

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

Answered By: poke

You haven’t defined a variable true. Maybe you meant the built-in boolean value True?

Answered By: phihag

while True:

# but seems like inifite loop

Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.