I'm wondering how I would go about finding the variable name of a dictionary element:
For example:
>>>dict1={}
>>>dict2={}
>>>dict1['0001']='0002'
>>>dict2['nth_dict_item']=dict1
>>>print dict2
{'nth_dict_item': {'0001': '0002'}}
>>>print dict2['nth_dict_item']
{'001': '002'}
How can I go about making it tell me that dict2['nth_dict_item'] is or is referencing "dict1" ? I want the name of the data structure it's referencing and not the data itself.
If I compare the output of id(dict1) to id(dict2['nth_dict_item']) I can find they are the same.
But how can I turn that id back into a variable name? Is there a more direct/cleaner method of getting the information that I want to know?
I'm sure I'm just overlooking a function that would make my life easy but I'm pretty new to Python :)
Any help is appreciated, thanks!
Related
Update: Here's why I wanted this to work:
I'm trying to make an app that uses a dictionary kinda like a database. I wanted the functionality of this psuedocode to function:
dict_1={}
dict_2={}
dict_3={}
dict_1["FooBar1.avi"]=[movie_duration,movie_type,comments]
dict_2["FooBar2.avi"]=[movie_duration,movie_type,comments]
dict_3["FooBar3.avi"]=[movie_duration,movie_type,comments]
dict_database[SomeUniqueIdentifier1]=dict_1
dict_database[SomeUniqueIdentifier2]=dict_2
dict_database[SomeUniqueIdentifier3]=dict_3
SomeUniqueIdentifier# would be a unique value that I'm using as a database key/unqiueID to look up entries.
I want to be able to update the "comments" field of FooBar1.avi by:
WhichDict= dict_database[SomeUniqueIdentifier1]
WhichDict[WhichDict.keys()[0]][2]='newcomment'
instead of having to do:
dict_database['SomeUniqueIdentifier1'][dict_database['SomeUniqueIdentifier1'].keys()[0]][2]='newcomment'
Thanks everyone. I now understand I was misunderstanding a LOT of basics (total brain fart). Will go back and fix the design. Thanks to you all!.