作者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
1F:推 AndCycle:是 __init__ 不是 _init_ 10/09 14:29
2F:→ qetuomj:原来,网页上写连续两个底线,真是阅读不仔细。感谢!! 10/09 14:34