I wrote the following python code and tried to use __main__ to initialize two class objects, but I got the following errors when running python classPerson.py. I wonder what's the correct way of initializing class objects in python.
Person(object): def __init__(self, name, salary): self.name = name self.salary = salary def getName(): return self.name def getSalary(): return self.salary if __name__ == '__main__': bob = Person('Bob Smith', 40000) sue = Person('Sue Funk', 35000) print 'bob makes a salary of %d' % (bob.getSalary) print 'sue's full name is %s' % (sue.getName) Errors:
Traceback (most recent call last): File "classTest1.py", line 1, in <module> class Person(object): File "classTest1.py", line 14, in Person bob = Person('Bob Smith', 40000) NameError: name 'Person' is not defined