从调用的函数中检索值

我正在使用Python3。

Let's say we have four functions, a, b, c and d. Now assume that the callstack is as following:

a calls b, which calls c, which calls d. Function d calculates a parameter x which is needed later on in function a, but other than that, x is completely irrelevant for b and c.

My question is, what is the best way to "get" the variable x to function a. Intuitively, I'd say that I could let all the functions return x too, and that way x becomes accessible in function a. However, this feels so "bad" because the parameter x is completely irrelevant for the other functions. Could I potentially work with pointers maybe? I just want to know the most professional way to solve such a case.

评论