ElementTree should parse string and file in the same way

Steven Bethard steven.bethard at gmail.com
Tue Jan 1 14:59:44 EST 2008


Steven D'Aprano wrote:
> 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.

I assume the problem with this is that it would be ambiguous. You can 
already use either a string or a file with ``et.parse``. A string is 
interpreted as a file name, while a file object is used directly.

How would you differentiate between a string that's supposed to be a 
file name, and a string that's supposed to be XML?

Steve



More information about the Python-list mailing list