Why am I getting AttributeError: Object has no attribute


I have a class MyThread. In that, I have a method sample. I am trying to run it from within the same object context. Please have a look at the code:

class myThread (threading.Thread): 

     def __init__(self, threadID, name, counter,



           self.threadID = threadID 

           self.name = name 

           self.counter = counter 

           self.redisOpsObj = redisOpsObj 

    def stop(self): 

          self.kill_received = True 

   def sample(self):

         print "Hello" 

   def run(self):


        print "\n Starting " + self.name 


Looks very simple ain't it. But when I run it I get this error

AttributeError: 'myThread' object has no attribute 'sample'

Now I have that method, right there. So what's wrong? Please help



In python, indentation is very important. If you mess it up, the code won't execute. So, specify the indentation properly.



If you want to unleash your potential in this competitive field, please visit the Python course page for more information, where you can find the Python tutorials and Python frequently asked interview questions and answers as well.


This topic has been locked/unapproved. No replies allowed

Login to participate in this discussion.

Leave a reply

Before proceeding, please check your email for a verification link. If you did not receive the email, click here to request another.