您的位置:首页 > 编程语言 > Python开发

TypeError: unbound method must be called with class instance 1st argument

2014-07-18 13:51 751 查看
引出此类型的错误可能很多,我的原因如下

1.定义一个Python类

class test:
def call_test(self):
print("test")


2. 使用类

test_instance = test()
test_instance.call_test()




创建实例的时候,忘记加上括号().所以出错,当然单独写出来的时候,很容易发现,但是在一个复杂逻辑的背景下,很难觉察。

正确的如下:

test_instance = test()
test_instance.call_test()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python
相关文章推荐