仅针对您的情况,解决方案是:
var = 'I need to be accessed by id!'address = id(var)print(address)var2 = [x for x in globals().values() if id(x)==address]
它也可以从类似
def get_by_address(address): return [x for x in globals().values() if id(x)==address]var = 'I need to be accessed by id!'address = id(var)print(address)var2 = get_by_address(address)
但正如其他人指出的那样: 首先,请确保没有更好的解决方案可以更好地满足您的需求
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)