我有2个文件Python: Pet.py
class Pet(object):
def __int__(self, name, species):
self.name = name
self.species = species
def getName(self):
return self.name
def getSpecies(self):
return self.species
def __str__(self):
return "%s is %s" % (self.name, self.species)
并提交petobject.py
from Pet import Pet
polly = Pet("Polly", "Parrot")
print "Polly is a %s" % polly.getSpecies()
当我运行petobject.py时出现此错误:object()不带参数。 请帮我解决这个错误。
答案 0 :(得分:1)
您的类初始化函数拼写错误,应该是__init__
而不是__int__
:
def __init__(self, name, species):