【发布时间】:2017-08-01 03:27:22
【问题描述】:
假设我有一个这样定义的函数:
def inner_func(spam, eggs):
# code
然后我想调用这样的函数:
outer_func(spam=45, eggs="blah")
在outer_func 内部,我希望能够使用传递给outer_func 的完全相同的参数调用inner_func。
这可以通过像这样写outer_func来实现:
def outer_func(spam, eggs):
inner_func(spam, eggs)
但是,我希望能够更改 inner_func 采用的参数,并相应地更改我传递给 outer_func 的参数,但不必每次都更改 outer_func 中的任何内容。
有没有(简单的)方法可以做到这一点?请使用 Python 3。
【问题讨论】:
-
我不确定我明白你想要做什么。似乎您希望
func_one调用func_two,有时您需要相同的参数,有时您需要不同的参数。这是模糊的。你能提供一个你想要的功能的例子吗? -
当你说“不改变
outer_func的定义”时,你的意思是每次改变inner_func都不改变它,还是你的意思是定义仍然应该说def outer_func(spam, eggs):完成后现在的情况如何? -
@user2357112 我的意思是第一个选项
标签: python python-3.x parameters arguments parameter-passing