EverybodyDies 2019-06-19 19:36 采纳率: 0%
浏览 467

jupyter notebook用不了@classmethod?

在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'

  • 写回答

1条回答 默认 最新

  • 莱撕粒 2022-01-20 07:58
    关注

    请问你知道为啥了吗? 我也遇到同样的问题

    评论

报告相同问题?

悬赏问题

  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图2.0 版本点聚合中Marker的位置无法实时更新,如何解决呢?
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题