作者qetuomj (哇係gary)
看板Python
標題[問題] Class 範例,不知道哪出錯
時間Fri Oct 9 14:21:57 2009
Hi.
我是新手中的新手
我目前按照
http://pydoing.blogspot.com/2008/10/blog-post_1288.html
了解Python
以下是CODE:
class Point(object):
def _init_(self,x=0,y=0):
self.x=x
self.y=y
def _str_(self):
return "("+str(self.x)+","+str(self.y)+")"
先編譯後
在Python Shell下輸入p1=Point(1,1)
卻出現
Traceback (most recent call last):
File "<pyshell#20>", line 1, in <module>
p=Point(1,1)
TypeError: object.__new__() takes no parameters
哪裡的問題呢?我對照這個教學的內容照著打上的
感謝大家寶貴的時間啦~
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 71.196.234.172
推 AndCycle:是 __init__ 不是 _init_ 10/09 14:29
→ qetuomj:原來,網頁上寫連續兩個底線,真是閱讀不仔細。感謝!! 10/09 14:34