TypeError: 'builtin_function_or_method' object is not subscriptable

后端 未结 8 1110
太阳男子
太阳男子 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:17

    This error arises when you don't use brackets with pop operation. Write the code in this manner.

    listb.pop(0)
    

    This is a valid python expression.

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

    Looks like you typed brackets instead of parenthesis by mistake.

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

    instead of writing listb.pop[0] write

    listb.pop()[0]
             ^
             |
    
    0 讨论(0)
  • 2020-12-09 02:22

    Mad a similar error, easy to fix:

        TypeError Traceback (most recent call last) <ipython-input-2-1eb12bfdc7db> in <module>
      3 mylist = [10,20,30] ----> 4 arr = np.array[(10,20,30)] 5 d = {'a':10, 'b':20, 'c':30} TypeError: 'builtin_function_or_method' object is not subscriptable
    

    but I should have written it as:

    arr = np.array([10,20,30])
    

    Very fixable, rookie/dumb mistake.

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

    I think you want

    listb.pop()[0]
    

    The expression listb.pop is a valid python expression which results in a reference to the pop method, but doesn't actually call that method. You need to add the open and close parentheses to call the method.

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

    You are trying to access pop as if was a list or a tupple, but pop is not. It's a method.

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