Question

elif( listb[0] == "-test"):
    run_all.set("testview")
    listb.pop[0]

ERROR: Exception in Tkinter callback Traceback (most recent call last): File "/tools/python/2.7.2/lib/python2.7/lib-tk/Tkinter.py", line 1410, in call return self.func(*args) File "./edit.py", line 581, in populate listb.pop[0] TypeError: 'builtin_function_or_method' object is not subscriptable

The line # 581 is represented by last pop statement in the code above. run_all is a StringVar.

Why am I getting this error and how can it be solved?

Was it helpful?

Solution

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.

OTHER TIPS

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

instead of writing listb.pop[0] write

listb.pop()[0]
         ^
         |

Looks like you typed brackets instead of parenthesis by mistake.

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top