Accessing the name of an actual parameter

Hellmut Weber mail at hellmutweber.de
Tue Jan 26 06:48:32 EST 2010


Hi,

consider the following piece of code, please

----- -----

def f(param):
   nameOfParam = ???
   # here I want to access the name of the variable
   # which was given as parameter to the function
   print nameOfParam, param
   return

if __name__ == __main__:

   a = 1
   f(a)

   b = 'abcd'
   f(a)

----- -----

The output should be:

'a' 1
'b' 'abcd'

----- -----

I tried to look at globals() and locals(), gave a look to the frames
(sys._getframe(0) and sys._getframe(1),
but did not see a possibility to access the information a want

How can this be done?

TIA

Hellmut


-- 
Dr. Hellmut Weber         mail at hellmutweber.de
Degenfeldstraße 2         tel   +49-89-3081172
D-80803 München-Schwabing mobil +49-172-8450321
please: No DOCs, no PPTs. why: tinyurl.com/cbgq




More information about the Python-list mailing list