Why am I getting AttributeError: Object has no attribute? [closed]
Your indentation is goofed, and you've mixed tabs and spaces. Run the script with python -tt
to verify.
If you’re using python 3+ this may also occur if you’re using private variables that start with double underscore, e.g., self.__yourvariable. Just something to take note of for some of you who may run into this issue.
These kind of bugs are common when Python multi-threading. What happens is that, on interpreter tear-down, the relevant module (myThread
in this case) goes through a sort-of del myThread
.
The call self.sample()
is roughly equivalent to myThread.__dict__["sample"](self)
. But if we're during the interpreter's tear-down sequence, then its own dictionary of known types might've already had myThread
deleted, and now it's basically a NoneType
- and has no 'sample' attribute.