1

I'm not sure I'm writing my program in correct way, but I have something like this:

unit_dict = {}
test_dict = {'a':unit_dict}

Now, when I access test_dict['a'] I get a reference (or is it pointer) to the correct dictionary, but is there a way at all to get the original object name somehow from test_dict?

Like:

magick_function(test_dict['a']) 
res > unit_dict = {}
kakk11
  • 898
  • 8
  • 21

1 Answers1

1

In some context, you could do something dirty with globals() like, but I doubt that there is not a better way for whatever you are trying to achieve in a wider context:

def magic(o):
  for k, v in globals().iteritems():
    if v is o:
      return k
  return None

> magic(test_dict['a'])
'unit_dict'
user2390182
  • 72,016
  • 6
  • 67
  • 89