gagsl-py2 at yahoo.com.ar
Fri Apr 9 20:33:07 CEST 2010
En Fri, 09 Apr 2010 01:13:37 -0300, Alf P. Steinbach <alfps at start.no>
> <code language="Py3">
> import urllib.request # urlopen
> import codecs # getreader
> import sys # stderr
> def text_stream_from( url, encoding ):
> text_reader = codecs.getreader( encoding )
> connection = urllib.request.urlopen( url )
> return text_reader( connection )
> def list_text( url, encoding ):
> lines = text_stream_from( url, encoding )
> for line in lines:
> print( line, end = "" )
> lines.close() # Undocumented?
> url = "http://www.rfc-editor.org/rfc/rfc1149.txt"
> list_text( url, "ascii" )
> First, I'm unable to find documentation that there /is/ a close method
> text_reader object, and I'm unable to find documentation that there is
> method in the file like connection object; is there such documentation?
codecs.getreader returns a StreamReader instance (see )
StreamReader is documented here  and it says "In addition to the above
methods, the StreamReader must also inherit all other methods and
attributes from the underlying stream." -- the stream being 'connection',
The 3.x version of the documentation in  doesn't provide any details
except being "a file-like object". The 2.x version  is much more clear:
"a file-like object is returned. This supports the following methods:
read(), readline(), readlines(), fileno(), close(), info(), getcode() and
geturl(). It also has proper support for the iterator protocol."
> Second, I'm unable to find documentation of when they're called and
> do. It seems that (A) when the connection object's st
method is called automatically, and (B) that when the
> text_reader object's close method is called it calls the close method
> wrapped stream (i.e. on the connection object). But where is this
I bet documentation patches are welcome.
More information about the Python-list