1 Apr 2010 22:41
Re: Temporary data attached to custom subclasses
Dave Kuhlman <dkuhlman <at> rexx.com>
2010-04-01 20:41:33 GMT
2010-04-01 20:41:33 GMT
> Date: Wed, 31 Mar 2010 10:34:34 +0200 > From: Stefan Behnel <stefan_ml <at> behnel.de> > To: lxml-dev <at> codespeak.net > Subject: Re: [lxml-dev] Tempory data attached to custom subclasses > > Dave Kuhlman, 29.03.2010 23:48: > > I've been using the custom subclasses capability of lxml. It's > > slick. > > > > I do, however, miss the ability to attach temporary data to the > > ElementBase subclasses. (see the warnings under "Element > > initialization" at http://codespeak.net/lxml/element_classes.html) > > > > I can, as suggested by the docs, add attributes or children to the > > underlying etree.Element, but that means that I'd have to strip > > that temporary data off when I want to serialize the tree. > > As long as your tree doesn't change, the easiest solution is to keep a > reference to all Elements ("list(root.iter())") and then just store the > data in the proxy instances. They are guaranteed not to change as long as > there is a live reference to them. > > If your tree changes, you can still try to add new Elements to your > keep-alive list to get the same behaviour, but you may need to take a > little more care when you remove elements, so that you only remove them > from the keep-alive list when you are sure they'll get discarded. > Stefan -(Continue reading)
RSS Feed