TypeError: 'builtin_function_or_method' object is not subscriptable

Ani picture Ani · Nov 30, 2011 · Viewed 276.3k times · Source
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?

Answer

srgerg picture srgerg · Nov 30, 2011

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.