list-like behaviour of etree.Element

Joshua.R.English at gmail.com Joshua.R.English at gmail.com
Mon Mar 5 12:51:12 EST 2007


On Mar 5, 1:00 am, "Fredrik Lundh" <fred... at pythonware.com> wrote:
> Raymond Hettinger wrote:
> > On Mar 4, 12:48 pm, "Daniel Nogradi" <nogr... at gmail.com> wrote:
> >> The etree.Element (or ElementTree.Element) supports a number of
> >> list-like methods: append, insert, remove. Any special reason why it
> >> doesn't support pop and extend (and maybe count)?
>
> > Those methods would not be hard to add.  Perhaps, submit a feature
> > request to Fredrik Lundh on SourceForge and see what he thinks there
> > is merit in more closely emulating the list API.  Of the methods you
> > listed, the case is probably strongest for extend().
>
> extend() will be in the next release:
>
>    http://effbot.org/zone/elementtree-changes-13.htm
>
> (lxml.etree already has it, btw).
>
> not sure I see the point of pop() and count().  a successful feature request
> would need to include some really compelling use cases.
>
> </F>

Pop could be useful.  I could use it.

I'm working on a story and submission tracker.  It stores everything
in XML and I use a sax parser to build reports.  If I have to update
one bit of data (say, a submission returns a sale) I have to use a
nasty extraction program that returns the submission node AND the rest
of the document (minus that node).  Then I make the changes of the
individual submission, and append it to the end of submissions data
document.  (I don't care about the order of items in the file, since
my reporting methods re-order everything anyway.)

Josh




More information about the Python-list mailing list