Re: Getting current variable name

2005-03-17 Thread Ron
Jeff Shannon wrote: Are you sure that you really need that single-element list? No I'm not sure, I thought I found a concdition where it made a difference while playing with it, but I don't recall just what circumstance it was? Don't forget, in Python, all names are references. You only have to

Re: Getting current variable name

2005-03-17 Thread Lonnie Princehouse
> There should be an easier way that doesn't require stepping though the name list. Trying to find names bound to a particular object is a /very/ strange thing to want to do in Python. If this is for anything more than debugging diagnostics, it's probably better to use a dictionary explicitly for

Re: Getting current variable name

2005-03-17 Thread Jeff Shannon
Ron wrote: def getvinfo(vars, v): """ vars is locals() v is [varable] Use an one item list to pass single varables by reference. """ for n in vars.keys(): if vars[n] is v[0]: return n, v[0], type(v[0]) a = 101 b = 2.3 c = True print getvinfo(locals(), [a]

Re: Getting current variable name

2005-03-16 Thread Ron
pl wrote: Hi all, I followed the mails entitled 'How to turn a variable name into a string?' in march 2005 posts as I have a similar problem. Use the locals() function instead of globals(). Thanks by the way, I was wondering how to do this also, your post, and Daniel pointing out 'is', helped me w

Re: Getting current variable name

2005-03-16 Thread Steven Bethard
pl wrote: I followed the mails entitled 'How to turn a variable name into a string?' in march 2005 posts as I have a similar problem. I have to get some list variable names at some point in my program. So I ended up looking into globals() to get them with a small function like this: #!/usr/bin/pyth

Re: Getting current variable name

2005-03-16 Thread Daniel Dittmar
pl wrote: I have to get some list variable names at some point in my program. So I ended up looking into globals() to get them with a small function like this: [...] var = globals().keys() for i in var : if globdict[i] == obj: print i Use 'is'

Getting current variable name

2005-03-16 Thread pl
Hi all, I followed the mails entitled 'How to turn a variable name into a string?' in march 2005 posts as I have a similar problem. I have to get some list variable names at some point in my program. So I ended up looking into globals() to get them with a small function like this: #!/usr/bin/pyth