list-like behaviour of etree.Element

D

Daniel Nogradi

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)?
 
R

Raymond Hettinger

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().


Raymond
 
F

Fredrik Lundh

Raymond said:
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>
 
D

Daniel Nogradi

The etree.Element (or ElementTree.Element) supports a number of
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.

Great! I also first thought of extend because that would be really
useful, pop and count just came to mind because they exist for lists.
But if extend will be added that'll already make life easier,
pop/count is probably not that much needed.
 
J

Joshua.R.English

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top