类初始化失败 [英] Class initialization failing

查看:93
本文介绍了类初始化失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

# Class and Instance Variables
class Dog:
    kind = 'canine'

    def __int__(self, name):
        self.name = name
        self.tricks = []

d = Dog('Fido')
e = Dog('Buddy')

print(d.kind)
print(e.kind)
print(d.name)
print(e.name)






错误报告:


Error report:

Traceback (most recent call last):
  File "dog.py", line 13, in <module>
    d = Dog('Fido')
TypeError: object() takes no parameters


推荐答案

您有错字。方法 __ int __ 应该称为 __ init __

You have a typo. The method __int__ should be called __init__.

这篇关于类初始化失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆