Is there anyway to get the names of passed arguments to a function in python?

前端 未结 6 2009
栀梦
栀梦 2021-01-06 15:50

I like to know what was the local variable names when they are passed to a function. I\'m not sure whether this is possible at all. Let\'s consider this example:

fun

6条回答
  •  情歌与酒
    2021-01-06 16:14

    No, you cannot know what the name was of the local variable used to pass a value to your function.

    This is an impossible task in any case. What would be the variable name in the following example?

    arguments = ('a', 1, 10)
    somefunction(*(arguments[:2] + [10]))
    

    Here we pass in 3 arguments, two taken from a tuple we defined earlier, and one literal value, and all three are passed in using the variable argument list syntax.

提交回复
热议问题