Re: Getting the name of a variable which was used as a function parameter.

2008-07-21 Thread Fredrik Lundh
Ravi Kotecha wrote: Of course I wouldn't, it is a total hack, mostly useless but fun. I tried to do it after someone in #python efnet said it was impossible! your function only finds *some* name (if it finds a name at all), not *the* name, so you haven't really proven that someone wrong yet.

Re: Getting the name of a variable which was used as a function parameter.

2008-07-21 Thread Ravi Kotecha
Of course I wouldn't, it is a total hack, mostly useless but fun. I tried to do it after someone in #python efnet said it was impossible! On Jul 21, 9:56 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > On Mon, 21 Jul 2008 09:01:10 -0700, Ravi Kotecha wrote: > > I thought this was pretty

Re: Getting the name of a variable which was used as a function parameter.

2008-07-21 Thread Marc 'BlackJack' Rintsch
On Mon, 21 Jul 2008 09:01:10 -0700, Ravi Kotecha wrote: > I thought this was pretty cool and since I spent 30 mins or so > goggling before giving up and figuring out myself I thought I'd share > it with you. > def a(a): > ... for k,v in sys._getframe(1).f_locals.items(): > ... if

Getting the name of a variable which was used as a function parameter.

2008-07-21 Thread Ravi Kotecha
Hi guys, I thought this was pretty cool and since I spent 30 mins or so goggling before giving up and figuring out myself I thought I'd share it with you. >>> def a(a): ... for k,v in sys._getframe(1).f_locals.items(): ... if id(v) == id(a): ... print k ... >>> hello = 12