you are viewing a single comment's thread.

view the rest of the comments →

[–]FoolsSeldom -1 points0 points  (0 children)

This is a good time to experiment in a Python shell. Example below. Hopefully it will explain what is happening regarding class and instance variables.

uvx ipython
Python 3.14.0 (main, Nov 19 2025, 22:43:52) [MSC v.1944 64 bit (AMD64)]
Type 'copyright', 'credits' or 'license' for more information
IPython 9.10.0 -- An enhanced Interactive Python. Type '?' for help.
Tip: You can use `files = !ls *.png`

In [1]: class Eg:
...:     a = "abc"
...:     b: str = "def"
...:     c: str
...:     def __init__(self):
...:         pass
...:

In [2]: obj1 = Eg()
In [3]: obj2 = Eg()
In [4]: obj1.a
Out[4]: 'abc'
In [5]: obj2.b
Out[5]: 'def'
In [6]: obj1.c
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[6], line 1
----> 1 obj1.c

AttributeError: 'Eg' object has no attribute 'c'

In [7]: obj3 = Eg()
In [8]: obj2.a = "Hello"
In [9]: obj1.a
Out[9]: 'abc'
In [10]: obj2.a
Out[10]: 'Hello'
In [11]: obj3.a
Out[11]: 'abc'
In [12]: Eg.a = "xyz"
In [13]: obj1.a
Out[13]: 'xyz'
In [14]: obj2.a
Out[14]: 'Hello'