Why am I getting AttributeError: Object has no attribute

Python

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,

     redisOpsObj):

           threading.Thread.__init__(self) 

           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):

        time.sleep(0.1) 

        print "\n Starting " + self.name 

        self.sample()

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
 


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.

1
Answers

Replies


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


 

 
 

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.
To Top