Python Forum
Translate to noob a Name Eroor message - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Translate to noob a Name Eroor message (/thread-25437.html)



Translate to noob a Name Eroor message - bako - Mar-30-2020

What exactly does this mean?

Error:
Traceback (most recent call last): File "waveshare_init.py", line 22, in <module> if cmd == off: NameError: name 'off' is not defined
"off" is cmd = sys.argv[1] which should be an option an option when I run the script. no?


RE: Translate to noob a Name Eroor message - stullis - Mar-30-2020

As written, the interpreter is looking for a variable named off. If you want to check for the string value, quotes are needed:

if cmd == "off":

# Or

if cmd == 'off':



RE: Translate to noob a Name Eroor message - bako - Mar-30-2020

Ah... stupid me. So, no quotes on variables. Specific values require quotes of some sort.