Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NameError: name 'true' is not defined [closed]

Tags:

python

gpio

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") 
like image 388
Jesper Andersen Avatar asked May 07 '15 07:05

Jesper Andersen


People also ask

How do you solve NameError name is not defined?

The Python "NameError: name is not defined" occurs when we try to access a variable or function that is not defined or before it is defined. To solve the error, make sure you haven't misspelled the variable's name and access it after it has been declared.

How do you correct a NameError in Python?

You can fix this by doing global new at the start of the function in which you define it. This statement puts it in the global scope, meaning that it is defined at the module level. Therefore, you can access it anywhere in the program and you will not get that error.

How do I fix NameError name NP not defined?

The Python "NameError: name 'numpy' is not defined" occurs when we use the numpy module without importing it first. To solve the error, install the module and import it ( import numpy ) before using it. Open your terminal in your project's root directory and install the numpy module.

What causes NameError in Python?

What Is a NameError in Python? In Python, the NameError occurs when you try to use a variable, function, or module that doesn't exist or wasn't used in a valid way. Some of the common mistakes that cause this error are: Using a variable or function name that is yet to be defined.


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

like image 166
poke Avatar answered Sep 30 '22 14:09

poke