Bugs That Bite
Published in

Bugs That Bite

NameError: name ‘xyz’ is not defined

Trying to use a variable that doesn’t exist in python

If you try to use a variable in a python statement that hasn’t yet been declared, you’ll get an error that the value is not defined.

Simply instantiate the variable to and empty string, 0, True, False, or None depending on what is appropriate for the datatype you’re using above the line that is getting the error.

xyz=""

I explained the importance of using the correct data type when it comes to application security here:

This error may drive you a bit crazy if you believe that you have, in fact, defined the variable. Double check your spelling….

If you are using a variable in a function and it was defined in another function, pass the variable into the function to use it and return it if you need to retain the new value.

xyz= test(xyz)function test(xyz):
xyz="something"
return xyz

This also threw me for a loop for a second when I got it on a line where I was defining a variale — or so I thought. I had typed this:

namel==name.lower()

See the problem? Should be:

namel=name.lower()

Teri Radichel

If you liked this story please clap and follow:

Medium: Teri Radichel or Email List: Teri Radichel
Twitter: @teriradichel or @2ndSightLab
Requests services via LinkedIn: Teri Radichel or IANS Research

© 2nd Sight Lab 2022

____________________________________________

Author:

Cybersecurity for Executives in the Age of Cloud on Amazon

Need Cloud Security Training? 2nd Sight Lab Cloud Security Training

Is your cloud secure? Hire 2nd Sight Lab for a penetration test or security assessment.

Have a Cybersecurity or Cloud Security Question? Ask Teri Radichel by scheduling a call with IANS Research.

Cybersecurity & Cloud Security Resources by Teri Radichel: Cybersecurity and Cloud security classes, articles, white papers, presentations, and podcasts

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store