Getting the name of a variable as a string

前端 未结 23 2712
旧时难觅i
旧时难觅i 2020-11-22 00:19

This thread discusses how to get the name of a function as a string in Python: How to get a function name as a string?

How can I do the same for a variable? As oppose

23条回答
  •  旧时难觅i
    2020-11-22 00:52

    You can try the following to retrieve the name of a function you defined (does not work for built-in functions though):

    import re
    def retrieve_name(func):
        return re.match("

提交回复
热议问题