1

If say I have something like:

myList = []

and a function:

def f(a):
    ...

and I call the function as such (where myList is still of List type):

f(myList)

then within this function itself, is there a way to obtain the name of the variable that is passed in? (i.e. can I get the value "myList" as a string from within the function?)

martineau
  • 119,623
  • 25
  • 170
  • 301
John Tan
  • 1,331
  • 1
  • 19
  • 35

1 Answers1

1

It's not possible. The name of the list holds the reference to the object, not the other way around.

Though if you know the contents of the list, you can do something like this:

a = ["kk","jj"]
for key,value in globals().iteritems():
  if type(value) == list and value == ["kk","jj"]:
    print key
Filipe Aleixo
  • 3,924
  • 3
  • 41
  • 74