TypeError: 'list' object is not callable in python

前端 未结 11 1715
醉梦人生
醉梦人生 2020-11-22 13:11

I am novice to Python and following a tutorial. There is an example of list in the tutorial :

example = list(\'easyhoss\')

Now

11条回答
  •  再見小時候
    2020-11-22 13:58

    I was getting this error for another reason:

    I accidentally had a blank list created in my __init__ which had the same name as a method I was trying to call (I had just finished refactoring a bit and the variable was no longer needed, but I missed it when cleaning up). So when I was instantiating the class and trying to call the method, it thought I was referencing the list object, not the method:

    class DumbMistake:
        def __init__(self, k, v):
            self.k = k
            self.v = v
            self.update = []
    
        def update(self):
            // do updates to k, v, etc
    
    if __name__ == '__main__':
        DumbMistake().update('one,two,three', '1,2,3')
    

    So it was trying to assign the two strings to self.update[] instead of calling the update() method. Removed the variable and it all worked as intended. Hope this helps someone.

提交回复
热议问题