What does the Python error “name 'self' is not defined” mean?

前端 未结 4 1847
心在旅途
心在旅途 2021-01-13 17:32

I can\'t figure out what\'s wrong with this very simple snippet:

class A(object):
        def printme(self):
                print \"A\"

        self.printm         


        
4条回答
  •  情深已故
    2021-01-13 17:54

    if you want to print something when you instantiate the object use:

    class A(object):
        def __init__(self):
                self.printme()
    
        def printme(self):
                print "A"
    
    a = A()
    

提交回复
热议问题