I want to use Boolean ( true / false ) in my python source file, but after running the application, I receive the following error:
JavaScript
x
2
1
NameError: name 'true' is not defined
2
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:
JavaScript
1
14
14
1
import RPi.GPIO as GPIO
2
import time
3
import os
4
5
inputSignal = 17
6
GPIO.setmode(GPIO.BCM)
7
GPIO.setup(inputSignal,GPIO.IN)
8
9
while true:
10
if (GPIO.input(inputSignal)):
11
os.system("html /home/pi/index.html")
12
else:
13
print("No Input")
14
Advertisement
Answer
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).