Hi:
I'm beginner in python scripting . i begin with learning python book .I write code below . this is an example of this book for oop programming .but i encounter to an error . I don't know what's my fault in this code . please help me.
this is error message :
Traceback (most recent call last):
File "<pyshell#1 0>", line 1, in <module>
class person:
File "<pyshell#1 0>", line 7, in person
bob = person('bob smith')
NameError: name 'person' is not defined
sincerely
I'm beginner in python scripting . i begin with learning python book .I write code below . this is an example of this book for oop programming .but i encounter to an error . I don't know what's my fault in this code . please help me.
Code:
class person:
def __init__(self,name,job=None,pay=0):
self.name = name
self.job = job
self.pay = pay
if __name__ == '__main__':
bob = person('bob smith')
print (bob.name, bob.pay)
Traceback (most recent call last):
File "<pyshell#1 0>", line 1, in <module>
class person:
File "<pyshell#1 0>", line 7, in person
bob = person('bob smith')
NameError: name 'person' is not defined
sincerely
Comment