PersistentList (ZODB)
Mike C. Fletcher
mcfletch at rogers.com
Tue Nov 19 15:22:39 EST 2002
Python isn't variable-typed, it's object-typed...
a = b
does not convert b to some particular type depending on 'a', and
probably won't unless/until we also get (hopefully optional) type
declarations for attributes. However:
a[:] = b
(replace all elements in a with the contents of b) might work for you.
Or, if you feel like it, you can use something like basicproperty,
which allows you to declare that a particular attribute of an object has
a particular type/class (and will be coerced to that type if necessary)
so that:
d.a = b
would do the conversion. However, that only works with ZODB4 (with Zope
3). You could probably cobble something together with __setattr__ hooks
for ZODB3 (Zope 2.x) that would do the same thing less elegantly. I
find, with basicproperty (which takes Python 2.2.2 properties and allow
you to declare types, upper/lower-bounds and the like for them) and
ZODB4 persistence is largely a "don't care" issue (modulo a few
annoyances regarding transaction boundaries for long-running connections).
Good luck,
Mike
Thomas Guettler wrote:
>Hi!
>
>I use PersistentList v1.3 from Zope2.6.
>
>If I do the following
>
>mylist=PersistentList()
>type(mylist)
>mylist.append(5)
>mylist=[1, 2, 3] # (*)
>type(mylist)
>
>mylist is not a PersistentList anymore. Is there
>a way to change PersistentList that way that the line
>marked with (*) does not delete the PersistentList,
>but creates a new empty one?
>
>This would bring me one big step towards programming nirvana:
> "Don't care for persistence!"
>
> thomas
>
>
>
--
_______________________________________
Mike C. Fletcher
Designer, VR Plumber, Coder
http://members.rogers.com/mcfletch/
More information about the Python-list
mailing list