A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2005-December/058725.html below:

[Python-Dev] ElementTree in stdlib

[Python-Dev] ElementTree in stdlibWalter Dörwald walter at livinglogic.de
Wed Dec 14 09:04:43 CET 2005
Guido van Rossum wrote:

> On 12/13/05, Walter Dörwald <walter at livinglogic.de> wrote:
>> Guido van Rossum wrote:
>>> I don't think that SAX is unpythonic, but it's pretty low-level and
>>> mostly of use to people writing higher-level XML parsers (my parsexml
>>> module uses it).
>> Having to define classes that conform to a certain API and registering
>> instances of those classes as callbacks with the parser doesn't look
>> that pythonic to me. An iterator API seems much more pythonic.
> 
> Perhaps. Although the SAX API lets you leave a callback undefined if
> you don't have a need to handle those events; that's a bit trickier to
> do with an iterator.

Changing the iterator to only generate the events you need requires 
passing information to the iterator. And when you do that you can just 
as well pass information about which function to call at which event.

But IMHO the main difference isn't dispatching, but who's in control.

> Also the different callbacks have different
> signatures.

True, I've always wondered why SAX uses a startelement callback which 
gets passed a complete attribute dictionary. IMHO for <foo 
bar="baz"/>spam</foo> the following event sequence would be better:

starttagbegin foo
attributebegin bar
text baz
attributeend bar
starttagend foo
text spam
endtag foo

This would simplify signatures (always one string argument) and it would 
leave handling entity references inside attribute values to the 
application (or at least a higher level of the parser).

> But since /F solved this for ElementTree I have to mostly agree with you. :-)

Unfortunately there probably won't be that many parsers that support 
iterparse(). Most parsers existing outside the Python world use the 
callback model and turning a callback parser into a iterator parser 
requires support for incremental parsing (which has a certain latency) 
or stack switching tricks.

>> Then again, pythonic is whatever you say that it is. ;)
> 
> Not at all. I will argue but I will also take arguments from others. Seriously.

Bye,
    Walter Dörwald

More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4