我知道Python的reduce函数只接受带有两个参数的函数。但是,是否有一种方法可以使更多的参数可用于该函数?我不想将其设置为全局变量,因为这会对所有其他导入可见。以下代码片段可能有助于描述问题(请阅读代码中的注释):
# The reduce function
def apply_something(something, config):
# Consrtuct a class object based on the truth value of some other variable.
# some_var can be changed and is being accessed in different threads so its
# not safe to make it global. The reduce function is being called from
# inside some other function so It would be better to make
# some_var only accessible in the function context.
if some_var:
obj = Klass(some_var)
else:
obj = Klass()
def callee():
# This is how I apply the reduce operation.
reduce(apply_something, [1, 2, 3], something_initializer)
# I want something like this:
some_var = True # So this can be accessed in apply_something
请提供关于这类问题的一些见解。