在jupyter notebook使用@classmethod报错
from datetime import date
class Person:
def __init__(self,name,age):
self.name = name
self.age = age
@classmethod
def formbirthYear(cls,name,birthYear):
return cls(name,date.today().year - birthYear)
def display(self):
print(self.name + "'s age is: + str(self.age)'")
person = Person.frombirthYear('John',19)
person.display()
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-11-fa496212bceb> in <module>()
10 print(self.name + "'s age is: + str(self.age)'")
11
---> 12 person = Person.frombirthYear('John',19)
13 person.display()
AttributeError: type object 'Person' has no attribute 'frombirthYear'