I want to do something like this:
fib = 1
foo = (arg):
print arg, argName # the name of the variable that was put in for arg
foo(fib)
And get this returned:
1, fib
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You cannot do it like that (as Ignacio Vazquez-Abrams already answered), but you can do it in a similar way:
The only difference is that you must use keyword arguments, otherwise it will not work.
The alternative solution is also to access
__name__attribute of passed variable, which will result in obtaining the name of function, class or name (or anything else that will have this name defined). The only thing that you should be aware of, is that by default this is not the name of the variable, but the original name of the function/class/module (the one assigned when it was being defined). See the example here: http://ideone.com/MzHNND