Disclaimer: what you are doing is most likely The Wrong Thing To Do
Your code worked before because (I assume) you were setting an attribute on a function object:
def foo():
foo.bar = 4
When run, the function object sets an attribute bar on itself. However, when you added the __setitem__ (with the square brackets):
def foo():
foo.bar[dor] = 4
You're now saying that you want to modify foo.bar, but foo.bar doesn't exist yet! You can "fix" this by setting up the object manually, before you run it for the first time:
def foo():
foo.bar[dor] = 4
foo.bar = {}
foo()
Most likely, you want to avoid this whole mess altogether by using a separate object to keep track of the recursion depth in your code. Just because you can do something doesn't mean you should.
EDIT: Looking at your code, it seems like you should be using a class instead of a function for parse. Using a class makes sense because you're encapsulating mutable state with a set of methods that act on it. Of course, I'm also obligated to point you to the standard library JSON module.
parseand you're modifying a variable calledparse, which refers to your function. Can you post all of your code?parse.indexetc are some attributes of this very functionparse, where are they assigned? You may want to consider a class instead.