getting an inputStream on a file

jano jnana4 at
Mon Aug 19 07:18:01 CEST 2002

"Peter Hansen" <peter at> wrote in message
news:3D605276.94935AD4 at
> jano wrote:
> >
> > Is there a way to get a stream on a file, for methods that require a
> > as input when I want to use a file as the input.
> What does "stream" mean to you in this context?  Which methods require
> a "stream"?
> -Peter

I was trying to do the following:

>>> from xml.dom.ext.reader.Sax2 import FromXmlStream
>>> doc = FromXmlStream("foosubset.xml")
Traceback (most recent call last):
  File "<pyshell#1>", line 1, in ?
    doc = FromXmlStream("foosubset.xml")
  File "C:\PYTHON22\Lib\site-packages\_xmlplus\dom\ext\reader\", line
387, in FromXmlStream
    return reader.fromStream(stream, ownerDocument)
  File "C:\PYTHON22\Lib\site-packages\_xmlplus\dom\ext\reader\", line
372, in fromStream
    s = saxutils.prepare_input_source(stream)
  File "C:\PYTHON22\Lib\site-packages\_xmlplus\sax\", line 463,
in prepare_input_source
    f = urllib.urlopen(source.getSystemId())
  File "C:\Python22\Lib\", line 73, in urlopen
  File "C:\Python22\Lib\", line 178, in open
    return getattr(self, name)(url)
  File "C:\Python22\Lib\", line 405, in open_file
    return self.open_local_file(url)
  File "C:\Python22\Lib\", line 412, in open_local_file
    stats = os.stat(localname)
OSError: [Errno 2] No such file or directory: 'foosubset.xml'

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 s
tdin redirection to get use that method on a file.


More information about the Python-list mailing list