[ Python弱引用 ]


weakref

本视频介绍了Python中的弱引用,即通过弱引用实现对对象引用计数,并在引用计数为零时将对象从字典中删除。同时,本视频还讲解了weak valid dictionary和weak key dictionary的概念和使用方法

import weakref

players = weakref.WeakKeyDictionary()

class Player:
    ...

# 报错
players[1]

# ???
players[Player]