How to get name of list

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aberry
    New Member
    • Sep 2008
    • 10

    How to get name of list

    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...

    rgds,
    Ab
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    You could iterate through the global dictionary for a list of equivalent value to get the name of the variable.

    [code=Python]>>> mca = ["kk","jj"]
    >>> for key,value in globals().iteri tems():
    ... if type(value) == list and value == ["kk","jj"]:
    ... print key
    ...
    mca
    >>> [/code]

    Comment

    • aberry
      New Member
      • Sep 2008
      • 10

      #3
      thanks bvdet
      ..u r Python guru :)

      have gr8 weekend !

      Comment

      Working...