Explore Courses Blog Tutorials Interview Questions
0 votes
in Python by (47.6k points)

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 

  = 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 " + 


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

1 Answer

0 votes
by (106k points)

You are getting this attribute error because your indentation is goofed, and you've mixed tabs and spaces. Run the script with python -tt to verify.

Browse Categories