gpt4 book ai didi

python - 如何将持久对象的基本类型属性排除在持久对象之外?

转载 作者:行者123 更新时间:2023-12-01 05:54:47 24 4
gpt4 key购买 nike

例如,如果类型是对象的 int 或 str 属性,您将如何将其排除在对象的类中。是不是必须在属性之前声明一个装饰器,那它是什么?

最佳答案

Persistent Rules:

  • Your objects, and their attributes, must be “pickleable”.
  • Your object cannot have any attributes that begin with ‘p’.
  • Attributes of your object that begin with _v_ are “volatile” and are not saved to the database (see next section).
  • You must explicitly signal any changes made to mutable attributes (such as instances, lists, and dictionaries) or use persistent versions of mutable objects, like
    ‘ZODB.PersistentMapping’

The third rule is that all object attributes that begin with _v_ are “volatile” and are not saved to the database. This means that as long as the persistent object is in Zope memory cache, volatile attributes can be used. When the object is deactivated (removed from memory) volatile attributes are thrown away.

Volatile attributes are useful for data that is good to cache for a while but can often be thrown away and easily recreated. File connections, cached calculations, rendered templates, all of these kinds of things are useful applications of volatile attributes. You must exercise care when using volatile attributes. Since you have little control over when your objects are moved in and out of memory, you never know when your volatile attributes may disappear.

关于python - 如何将持久对象的基本类型属性排除在持久对象之外?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13079904/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com