Python: class attributes haven’t been found after defining

I’m making a Tick Tack Toe game using classes in Python. A function inside of the class can’t find attributes (I have set them, of course). I was only testing it now to see if the class works for me but it doesn’t. What’s wrong?

class ttt_sqs:
def __init__(self, column, row):
    self.column = column
    self.row = row

def position(self, column, row):
    self.position = self.column + self.row

from ttt_sqs import *

A1 = ttt_sqs("A", "1")
print(A1.position(ttt_sqs.column(), ttt_sqs.row()))

Answer

class ttt_sqs:
def __init__(self, column, row):
    self.column = column
    self.row = row

def position(self, column, row):
    self.position = self.column + self.row

from ttt_sqs import *

A1 = ttt_sqs("A", "1")
print(A1.position(A1.column, A1.row))

the row and column are object attributes, not functions. Also they are not static variables to be accessed using class name, hence you have to refer them using object.

Hope this solves your problem.

Leave a Reply

Your email address will not be published. Required fields are marked *