python – Why am I getting AttributeError: Object has no attribute?

python – Why am I getting AttributeError: Object has no attribute?

Your indentation is goofed, and youve 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.

python – Why am I getting AttributeError: Object has no attribute?

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 were during the interpreters tear-down sequence, then its own dictionary of known types mightve already had myThread deleted, and now its basically a NoneType – and has no sample attribute.

Leave a Reply

Your email address will not be published. Required fields are marked *