How to retrieve a variable's name in python at runtime?

后端 未结 8 1490
悲哀的现实
悲哀的现实 2020-11-28 13:33

Is there a way to know, during run-time, a variable\'s name (from the code)? Or do variable\'s names forgotten during compilation (byte-code or not)?

e.g.:



        
8条回答
  •  日久生厌
    2020-11-28 13:58

    Variable names persist in the compiled code (that's how e.g. the dir built-in can work), but the mapping that's there goes from name to value, not vice versa. So if there are several variables all worth, for example, 23, there's no way to tell them from each other base only on the value 23 .

提交回复
热议问题