getting an inputStream on a file

Erik Max Francis max at alcyone.com
Mon Aug 19 01:37:11 EDT 2002


jano wrote:

> It works fine if the method is FromXmlStream(sys.stdin), but I wanted
> to use
> a file, and I wondered if it was possible to get a stream (like an
> InputStream in Java) on a file in order to satisfy the method.
> Perhaps this
> is a Java idiom that doesn't translate well into Python.  The
> signature of
> the method I wanted to use was
> FromXmlStream(stream, ownerDocument=None, validate=0, keepAllWs=0,
> catName=None, saxHandlerClass=<class
> xml.dom.ext.reader.Sax2.XmlDomGenerator
> at 0x00995690>, parser=None), so i thought there might be a way other
> than stdin redirection to get use that method on a file.

By "stream," they really just mean a "file object," of which sys.stdin
is an example.  You're passing in a filename, which isn't the same
thing.  Instead, all you need to do is create a file with it:

	FromXmlStream(file(sys.stdin))

or

	FromXmlStream(open(sys.stdin))

for older versions of Python.

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE
/  \ There is nothing so subject to the inconstancy of fortune as war.
\__/ Miguel de Cervantes
    Church / http://www.alcyone.com/pyos/church/
 A lambda calculus explorer in Python.



More information about the Python-list mailing list