I was trying kivy and while I was accessing class variables, I was forced to use ‘self’ for class variables or else it was producing error.
This is the kivy code I was using. Below is the main.py code where I have confusion:
This code works. Here I am using class variables and accessing them from ‘self’.
According to me the code that should work is:
OR
But both of these codes give error. What is it that I am doing wrong?
Advertisement
Answer
Kivy properties are Python descriptors, an object supporting a special api that let’s them provide instance-level behaviour when accessed from a class instance.
I think you also have a misconception about class vs instance level variables: variables defined at class level are also accessible via instances of the class, it’s normal that you can access self.something_defined_at_class_level
.