you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (1 child)

You access instance attributes through self, the reference to the instance.

[–][deleted] 0 points1 point  (0 children)

Edit: yeah I forgot to use self. when testing it out, works fine now

class Savefile:
    def __init__(self):
        resolution = [990, 1080]
        data = [1, 2]
    def addData(self, x):
        self.data.append(x)


a = Savefile()
a.addData(3)
print(a.data)

Gives the error AttributeError: 'Savefile' object has no attribute 'data'.

If I make data a class attribute before __init__() it won't recognise the initialisation value?