ElementTree should parse string and file in the same way

Chris Mellon arkanes at gmail.com
Wed Jan 2 13:29:07 EST 2008


On Jan 2, 2008 8:56 AM, Fredrik Lundh <fredrik at pythonware.com> wrote:
> Steven D'Aprano wrote:
>
> > Fredrik, if you're reading this, I'm curious what your reason is. I don't
> > have an opinion on whether you should or shouldn't treat files and
> > strings the same way. Over to you...
>
> as Diez shows, it's all about use cases.
>
> and as anyone who's used my libraries or read my code knows, I'm a big
> fan of minimalistic but highly composable object API:s and liberal use
> of short helper functions to wire them up to fit the task at hand.
>
> kitchen sink API design is a really bad idea, for more reasons than I
> can fit in this small editor window.
>

On that note, I really don't like APIs that take either a file name or
a file object - I can open my own files, thanks. File objects are
fantastic abstractions and open(fname) is even shorter than
StringIO(somedata).

My take on the API decision in question was always that a file is
inherently an XML *document*, while a string is inherently an XML
*fragment*.



More information about the Python-list mailing list