ElementTree should parse string and file in the same way
Steven D'Aprano
steve at REMOVE-THIS-cybersource.com.au
Tue Jan 1 09:45:58 EST 2008
On Tue, 01 Jan 2008 13:36:57 +0100, Diez B. Roggisch wrote:
> And codemonkeys know that in python
>
> doc = et.parse(StringIO(string))
>
> is just one import away
Yes, but to play devil's advocate for a moment,
doc = et.parse(string_or_file)
would be even simpler.
Is there any reason why it should not behave that way? It could be as
simple as adding a couple of lines to the parse method:
if isinstance(arg, str):
import StringIO
arg = StringIO(arg)
I'm not saying it *should*, I'm asking if there's a reason it *shouldn't*.
"I find it aesthetically distasteful" would be a perfectly acceptable
answer -- not one I would agree with, but I could accept it.
--
Steven
More information about the Python-list
mailing list