How to write a function to return the variable name?

后端 未结 6 1363
自闭症患者
自闭症患者 2020-12-04 03:59

I want a function that can return the variable/object name as str like this :

def get_variable_name (input_variable):
    ## some codes

>>get_variable         


        
6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-04 04:38

    If your statement to be used in exec() is something like this

    a = ["ffffd","dfd","444"]
    

    then do something like this

    exec('b = a = ["ffffd","dfd","444"]')
    

    now you can use 'b' in your code to get a handle on 'a'.

提交回复
热议问题