这似乎是一件相当奇怪的事情,但我很好奇是否可以在 Python 中将变量隐式传递到调用链而不将其作为参数传递。为了更好地说明这里是一个例子:
这是“正常”的方式:
def three(something):
    print(something)
def two(something):
    # ...
    three(something)
def one(something):
    # ...
    two(something)
这就是我想要做的:
def three():
    # something is defined implicitly
    print(something)
def two():
    # ...
    three()
def one(something):
    # somehow define something inside a context
    # for this activation 
    two()
为此one,two和three不在同一类甚至同一模块中。