2017-06-18 189 views
0
# 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) 

錯誤報告:類的初始化失敗

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

錯字:'__int__'應該是'__init__'。 – tom

+0

非常感謝!我糾正了你指出的錯誤。 – chentaocuc

+0

不客氣:)我重新發表我的評論作爲答案。如果您的問題已解決,請隨時[將答案標記爲已接受](https://meta.stackexchange.com/a/5235)。否則,請在您的問題中添加詳細信息或提出新問題。 – tom

回答

4

你有一個錯字。方法__int__應該被稱爲__init__