[ZODB-Dev] property broken with/by ZODB?

Chris Cioffi evenprimes at gmail.com
Tue Aug 17 14:39:41 EDT 2004


I'm converting a bunch of dicts into proper classes and am having some
problems using the property builtin.  When I derive the class from
Persistent my properties don't work.  Here's an example:

import os.path

import ZODB
from Persistence import Persistent

class PersistentProp(Persistent):
   def __init__(self):
       self.filename = 'c:\\somedir\\somefile.txt'

   def get_basename(self):
       return os.path.basename(self.filename)

   basename = property(get_basename)

class ObjectProp(object):
   def __init__(self):
       self.filename = 'c:\\somedir\\somefile.txt'

   def get_basename(self):
       return os.path.basename(self.filename)

   basename = property(get_basename)

if __name__ == '__main__':
   obj = PersistentProp()
   print 'The Persistent aware object'
   print obj.basename

   obj = ObjectProp()
   print 'The "normal" object'
   print obj.basename

When I run this I get:
The Persistent aware object
<property object at 0x00891288>
The "normal" object
somefile.txt

Since the whole point is to keep this as transparent as possible to
the rest of the code having to go back in and make some things method
calls and others attribute references it rather hurts long term
maintainability.

Any ideas on what's going on here?

Thanks!

Chris
-- 
Still searching for an even prime > 2!


More information about the ZODB-Dev mailing list