如果你把下面的简单类:Python的新手 - 理解类函数
class AltString:
def __init__(self, str = "", size = 0):
self._contents = str
self._size = size
self._list = [str]
def append(self, str):
self._list.append(str)
def output(self):
return "".join(self._list)
我用成功调用类的实例:
as = AltString("String1")
as.append("String2")
as.append("String3")
当我然后调用使用as.output
代替output
功能的字符串返回,我得到以下代替:
unbound method AltString.output
,如果我把它用as.output()
我得到以下错误:
TypeError: unbound method output() must be called with
AltString instance as first argument (got nothing instead)
什么我没有做对吗?
您正在编写'StringIO.StringIO'类。 – 2009-10-14 13:49:50
REwriting;)...... – 2009-10-14 13:53:50
那么,首先你的代码中没有类方法。你的代码工作得很好。所以你做错了它最有可能不给我们实际的代码。 ;) – 2009-10-14 13:54:18