cElementTree.interparse() doesn't accept custom parser
Question: I parse XML file on Python with ElementTree. I found out that C implementation
of cElementTree work very fast comparing to regular one. But I have also
discovered construction:

    
    
    xml.etree.cElementTree.iterparse(filename, parser=MyCystomParser())
    

wont work. You will see something like:

    
    
    __init__() got an unexpected keyword argument 'parser'
    

Meanwhile same construction with 'xml.etree.ElementTree.iterparse' does work.

I use custom parser to keep comments while parsing XML file (default parser
ignores/removes it).

Does anyone know why in C implementation it doesn't work? The 'parser'
argument was already in ElementTree when cElementTree released.


Answer: > Does anyone know why in C implementation it doesn't work?

Well, yeah, because it's
[_documented_](http://docs.python.org/2.7/library/xml.etree.elementtree.html#xml.etree.ElementTree.iterparse)
to not work:

> _parser_ is not supported by `cElementTree`.

But why didn't they make it work?

The version of ElementTree that was incorporated into Python 2.5 did not have
a `parser` argument on `iterparse`. This feature was only added in Python 3.2.
It was then backported to Python 2.7.* (Note that it's not there in
[2.6](http://docs.python.org/2.6/library/xml.etree.elementtree.html#xml.etree.ElementTree.iterparse).)

Python 3.x does not have `cElementTree`—instead, it just has a single
`ElementTree` implementation, with C accelerator code that it uses wherever
possible. So, it would have been much more work to backport the new feature to
`cElementTree` than to `ElementTree`. And presumably it wasn't important
enough for anyone to bother doing.

Also, note that ElementTree is developed and maintained outside of Python's
stdlib, by Frederik Lundh, [here](http://effbot.org/zone/element-index.htm). I
believe Gregory P. Smith drives the integration-into-the-stdlib work, but I
could be wrong. So, you could ask either of them, or ask on the python-dev
list, if you want any more details. But I'm pretty sure the answer will just
be "it wasn't important enough to bother doing".

* * *

* Technically, it was added in ElementTree 1.3, the version incorporated into Python 3.2 and 2.7. See the What's New docs for [2.7](http://docs.python.org/3.3/whatsnew/2.7.html#updated-module-elementtree-1-3) and [3.2](http://docs.python.org/3.3/whatsnew/3.2.html#elementtree).

