Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想知道我们是否可以为存储在 ZODB 中的所有对象提供唯一标识符
存储在 ZODB 中的每个对象都有一个唯一的 ID,在对象注册后可作为其 _p_oid 属性访问:
>>> obj._p_oid
关于主键的常见警告适用——如果您需要一个可以继续使用的唯一标识符,即使您需要将对象导出到不同的数据库,您最好使用您自己管理的 uuid。Python 有一个可以生成 uuid 的 uuid 模块(在 Python 2.6 的 stdlib 中)。