Name not defined?

I’m trying to call a class method that takes 3 arguments. However, after I instantiate the class and call it with the method I’m getting a NameError: name ‘lions’ is not defined, even though ‘lions’ is a class variable. I thought class variables were available to be called in any instantiation of the class??..

My code
class Points():
lions_vs_cobras = [24, 36]
lions = 24
cobras = 36

def game_score(self, points_scored, team):
    if team == self.lions:
        self.lions_vs_cobras[0] += points_scored
        self.lions += points_scored
    elif team == self.cobras:
        self.lions_vs_cobras[1] += points_scored
        self.cobras += points_scored

game_one = Points()
team_name = Points()
game_one_scores = game_one.game_score(24, lions)

Before you argue that you’ve created it as a class variable, is the problem that you’re unable to get it from the class? Take a look at where the error happens and what that code is doing at that time.

Is the issue that I have more than 1 variable defined under my defined class? In other words, can there only be one class variable?

Nothing to do with your class.
You can delete the class and get the same error message.
Look at the error message. Where does it happen? Which variable?

File “”, line 51, in
game_one_scores = game_one.game_score(24, lions)
NameError: name ‘lions’ is not defined

And I’m confused why because I have this defined before it…
class Points():
lions_vs_cobras = [24, 36]
lions = 24
cobras = 36

which I thought was me defining “lions”

class Thing:
    a = 3  # this is not a global variable, it does not define a outside the class

print(Thing.a)  # this is defined.
print(Thing().a)  # this is also defined.
print(a)  # haven't defined a anywhere

ohhhhh. That worked. very helpful. Thank you.

and going back to the example I provided. I thought this may work, but it doesn’t
after class and method

lions = Points()
#and then use that instantiated variable lions in my call

object attributes are like a dictionary. in fact, it is by default implemented as a dictionary

if something is not found as an attribute on an object, the class is checked afterwards. in case of methods, the class will bind the method to the object first. the class’s attributes are also a dictionary.

so if you want an attribute to exist in one of those dicts, put it there. and putting it there doesn’t put it anywhere else.

method binding just means that instead of getting a normal function, you get a function that is associated with the object - it is partially applied with the object as the first argument to the method

unbound_method = Thing.method  # got it from the class, still unbound
bound_method = Thing().method  # got it through an instance, it's bound to that instance