Why am I receiving the error ‘Object has no attribute error in Python’?

185    Asked by DaniloGuidi in Python , Asked on Aug 8, 2023
There is a class MyThread. I am trying to run the method sample from the same object context. Here’s the code:
Class mythread (threading,thread):
Def _init_9self, threadID, name, counter,
self.threadID = ThreadID
Self.name = name
Self.counter = counter
self.redis0psObj = redis0psObj
Def stop (self):
Self.kill_received = True
Def sample (self):
Print “hello”
Def run (self):
Time.sleep (0.1)
Print “n Starting “ + self.name
On running, I am receiving the error
AttributeError : ‘my thread’ object has no attribute “sample”

What’s wrong?

Answered by Danna sahi

When you get an object with no attribute error then the cause is the indentation is goofed and you have probably blended tabs with spaces. You need to run the script with python -tt to check. The Python online training offered at JanBask Training gives you an experience like offline classes thereby saving the students from the tiring journey to travel to the physical locations. The course provides a total Python discipline’s preparation by touching on every core concept from basic to advanced thereby making your job ready to face the tough competitive market.

Your Answer


Parent Categories