Lijin Durairaj
Lijin Durairaj

Reputation: 5240

NameError: name 'main' is not defined - Is it the indentation?

I am new to python and this question has been asked before

  1. nameError name is not defined
  2. NameError: name '' is not defined
  3. NameError name 'Views' is not defined

but i have a different situation, this is my program

class student:    
    def address(self):
        print('address is mumbai')

    def contact(self):
        print('email : [email protected]')

    def main(self):
        _student=student()
        _student.address()
        _student.contact()    

if __name__ == "__main__":
    main()

i dont know if it is my indentation that is causing problem or it has something to do with the scope of the method

Upvotes: 0

Views: 4349

Answers (1)

TheDude
TheDude

Reputation: 3952

main is a method inside of the class student, so you need to change where main is defined.

class student:    
    def address(self):
        print('address is mumbai')

    def contact(self):
        print('email : [email protected]')

def main():
    _student=student()
    _student.address()
    _student.contact()

Upvotes: 3

Related Questions