logo       
Google Custom Search
    AddThis Social Bookmark Button
-->

Re: CSS and lxml: msg#00068

Subject: Re: CSS and lxml
Frederik Elwert wrote:
> Am Montag, den 17.09.2007, 16:37 +0200 schrieb Stefan Behnel:
>> If you don't want to alter the tree, you can use a dict to map Elements to a
>> style dict. However, note that Elements are not currently weak referenceable,
>> so you'd have to make sure the trees are discarded after use.
> 
> Erm, I must confess, I'm not sure what this means, practically speaking.
> Is it enough to "del" the dict after use?

Yes. If you use a per-tree dict and delete it when you delete the tree, you
will be fine.

Weak referencing means that the reference does not count for garbage
collection, so when the Element is no longer used, it will not be kept alive
only by the reference in the dict. See the weakref module.


>> You can also store style information in the tree under a separate namespace.
> 
> Hm, true. I have to think about that, since it would introduce some
> redundancy, but it might be the easiest way to go.

That's what lxml.objectify does for type annotations. It also provides
annotate() and deannotate() functions to annotate everything and to clean up
the tree when you're done.

Stefan


<Prev in Thread] Current Thread [Next in Thread>