In a large program that I've been working on, I ran into an attribute error:
line 154, in __ExtINT
DebugVar=Self.__Preset # Originally, I had Self.__Preset directly in an if statement. I added this line and put DebugVar in the if statement, so I could be sure what was causing the error.
AttributeError: '__Readitem' object has no attribute '_ReadItem__Preset'
I was sure that it was set in the __init__
function, and spent a while trying to work out why I was getting this error. When I discovered that python uses a dictionary to store all its variables, so I put print(Self.__dict__)
before the line that caused the error, so I could see what attributes did exist. I was surprised to see , '_Readitem__Preset': True}
in the dictionary. Why is it saying saying that it doesn't exist, in the error then?
I tried DebugVar=Self.__dict__['_Readitem__Preset']
instead of DebugVar=Self.__Preset
, and got:
line 154, in __ExtINT
DebugVar=Self.__dict__['_Readitem__Preset']
KeyError: '_Readitem__Preset'
I then tried putting self.__Preset=False
straight after __init__
, so that I could be sure that it does exist.
It might be worth mentioning that before I tried to manually extract the value from the variable, 2 dictionaries were displayed, meaning that originally the code worked once. After I changed the code, only one dictionary was displayed.
Is there anyone who has encountered this problem themselves, or has any idea as to why this is happening?