您当前的位置: 首页 >  Python

Xavier Jiezou

暂无认证

  • 3浏览

    0关注

    394博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

【Python】TypeError: ‘str‘ object is not callable(报错解决方案)

Xavier Jiezou 发布时间:2022-01-25 00:05:28 ,浏览量:3

项目场景
class Test():
    def __init__(self, color):
        self.color = color
        self.color()

    def color(self):
        print('color')


if __name__ == '__main__':
    Test('test')
问题描述
TypeError: 'str' object is not callable
原因分析

类属性与类方法重名,导致引用错误。

解决方案

避免类属性与类方法重名,修改为不同的值。

温馨提示

本文仅给出了引起 TypeError: 'str' object is not callable 报错的一种可能的情况(即类属性与类方法重名),其他原因也可能导致该错误。

引用参考

http://www.jsphp.net/python/show-24-204-1.html

关注
打赏
1661408149
查看更多评论
立即登录/注册

微信扫码登录

0.1327s