0

我收到以下错误:

TypeError:“int”对象不可调用

response = receiver(signal=self, sender=sender, **named) File "/Users/user/Documents/workspace/LiveWireSMS/sms/models/message.py", line 156, in my_handler instance.charge = instance.length (实例.内容)

从这段代码中:

@receiver(pre_save, sender=Message)
def my_handler(sender, **kwargs):
    instance = kwargs['instance']
    if not instance.charge:
        instance.charge = instance.length(instance.content)

这是它的调用函数:

@property
def length(self):
    return len(self.content) / 160 + 1

有人可以解释错误吗?谢谢你。

4

1 回答 1

3

您收到此错误是因为length返回一个int对象并且您尝试调用它。

instance.charge = instance.length # instead of instance.length(instance.content) 
于 2013-03-26T19:26:33.337 回答