📜  python 获取对象名称 - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:30.268000             🧑  作者: Mango

代码示例2
def name_of_object(arg):
    # check __name__ attribute (functions)
    try:
        return arg.__name__
    except AttributeError:
        pass

    for name, value in globals().items():
        if value is arg and not name.startswith('_'):
            return name