By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,701 Members | 1,970 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,701 IT Pros & Developers. It's quick & easy.

How to get name of list

P: 10
Hi all,

In my script , I need to get name of list Im using

eg. sat I have following list ...
mca = ["kk","jj"]

Now I want to get name of the list i.e. just 'mca'.
Do anyone know any method/attribute so that I can get name of list

NOTE: 'classobj' has in built method '__name__' which gives name of class but Im not able to find anything similar for list

Thanks in advance...

Nov 14 '08 #1
Share this Question
Share on Google+
2 Replies

Expert Mod 2.5K+
P: 2,851
You could iterate through the global dictionary for a list of equivalent value to get the name of the variable.

Expand|Select|Wrap|Line Numbers
  1. >>> mca = ["kk","jj"]
  2. >>> for key,value in globals().iteritems():
  3. ...     if type(value) == list and value == ["kk","jj"]:
  4. ...         print key
  5. ...         
  6. mca
  7. >>> 
Nov 14 '08 #2

P: 10
thanks bvdet
..u r Python guru :)

have gr8 weekend !
Nov 14 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.