Error: 'function' object is not subscriptable
python
Solution
It's impossible to say for sure without the full traceback, but most likely this is your problem:
v = evalTerm[env, f]
`evalTerm` is a recursive function that you would need to call (note the additional `()` instead of `[]` ):
v = evalTerm(env, f)
Square brackets `[ ]` in Python are used for subscription or indexing - that means, for example addressing a value in a dictionary by its key, or an item in a list by its index.
If you get the exception `'foo' object is not subscriptable` that means that you tried to use subscription for an object of type `'foo'` that doesn't support it.
Problem
I am doing my python assignment, but there is an error when I wanted to test the case above. Here is my code: ``` def evalTerm(env, t): if type(t) == Node: for label in t: children = t[label] if label == 'Number': t = children[0] return t elif label == 'Add': t1 = children[0] v1 = evalTerm(env, t1) t2 = children[1] v2 = evalTerm(env, t2) return v1 + v2 elif label == 'Multiply': t1 = children[0] v1 = evalTerm(env, t1) t2 = children[1] v2 = evalTerm(env, t2) return v1 * v2 elif label == 'Variable': x = children[0] if x in env: return env[x] else: print(x + " is unbound") exit() elif label == 'Int': f = children[0] v = evalTerm[env, f] if v == 'True': return 1 elif v == 'False': return 0 elif label == 'Parens': x = children[0] v = evalTerm(env, x) return v elif type(f) == Leaf: if f == 'True': return 'True' if f == 'False': return 'False' ``` When I test it by using: ``` evalTerm({}, {'Int': ['True']}) ``` it gives an error: 'function' object is not subscriptable How could I fix it?