TypeError: 'builtin_function_or_method' object is not subscriptable

后端 未结 8 1111
太阳男子
太阳男子 2020-12-09 02:06
elif( listb[0] == \"-test\"):
    run_all.set(\"testview\")
    listb.pop[0]

ERROR: Exception in Tkinter callback T

相关标签:
8条回答
  • 2020-12-09 02:33

    FYI, this is not an answer to the post. But it may help future users who may get the error with the message:

    TypeError: 'builtin_function_or_method' object is not subscriptable

    In my case, it was occurred due to bad indentation.

    Just indenting the line of code solved the issue.

    0 讨论(0)
  • 2020-12-09 02:39

    Can't believe this thread was going on for so long. You would get this error if you got distracted and used [] instead of (), at least my case.

    Pop is a method on the list data type, https://docs.python.org/2/tutorial/datastructures.html#more-on-lists

    Therefore, you shouldn't be using pop as if it was a list itself, pop[0]. It's a method that takes an optional parameter representing an index, so as Tushar Palawat pointed out in one of the answers that didn't get approved, the correct adjustment which will fix the example above is:

    listb.pop(0)
    

    If you don't believe, run a sample such as:

    if __name__ == '__main__':
      listb = ["-test"]
      if( listb[0] == "-test"):
        print(listb.pop(0))
    

    Other adjustments would work as well, but it feels as they are abusing the Python language. This thread needs to get fixed, not to confuse users.

    Addition, a.pop() removes and returns the last item in the list. As a result, a.pop()[0] will get the first character of that last element. It doesn't seem that is what the given code snippet is aiming to achieve.

    0 讨论(0)
提交回复
热议问题