Reputation: 7639
I wanted to know if we can have a unique identifier for all objects that are stored in ZODB
Upvotes: 1
Views: 583
Reputation: 5432
Each object stored in the ZODB does have a unique ID, accessible as its _p_oid attribute after the object has been registered:
>>> obj._p_oid
The usual caveats about primary keys apply -- if you need a unique identifier that you can continue to use even if you need to export your objects to a different database, you're better off using a uuid that you manage yourself. Python has a uuid module (in the stdlib as of Python 2.6) which can generate uuids.
Upvotes: 3