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

前端 未结 6 2011
栀梦
栀梦 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:21

    I like the answer to this question that's found in the Python programming FAQ, quoting Fredrik Lundh:

    The same way as you get the name of that cat you found on your porch: the cat (object) itself cannot tell you its name, and it doesn’t really care – so the only way to find out what it’s called is to ask all your neighbours (namespaces) if it’s their cat (object)...

    ....and don’t be surprised if you’ll find that it’s known by many names, or no name at all!

提交回复
热议问题