为什么提示错误
class Person(object):
def _init_(self,name,title,job):
self.name=name
self.title='Mr'
self.job='Student'
P = Person('Bob')
print P.name
class Person(object):
def _init_(self,name,title,job):
self.name=name
self.title='Mr'
self.job='Student'
P = Person('Bob')
print P.name
2017-01-17
class Person(object):
def __init__(self, name, score):
self.name = name
self.__score = score
p = Person('Bob', 59)
try:
print p.name
print p.__score
except AttributeError:
print 'attributeerror'
自己明白就行了,加个try except包围一下,输出attributeerror, 他这个又要输出attributeerror,还要运行成功,你就捕获一下错误,捕获输出attributeerror,这样attributeerror有了,也运行成功了
举报