[Tutor] urlopen: where are the results?

Kermit Rose kermit at polaris.net
Thu Mar 23 16:36:08 CET 2006

From: Danny Yoo
Date: 03/23/06 00:08:25
To: Kermit Rose
Cc: tutor at python.org
Subject: Re: [Tutor] urlopen: where are the results?
We can use 'import urllib2', or if we really want urlopen():
from urllib2 import urlopen

> >>> urlopen("http://www.kermitrose.com")
> <addinfourl at 13510096 whose fp = <socket._fileobject object at
> 0x00CDD768>>
This is fine so far.  What we're getting back is a file-like object.  But
Once we have this, we can use all the file-like methods we know about,
like read(), in order to pull out things from the file object.

Ah so.      

should I have assigned a name to the file by
website = urlopen(" http://www.kermitrose.com" )           ?

Since I did not assign a name,  would I be able to use any of the
given in the value of the function to access the file?


(Aside: the reason that urlopen() doesn't give us the file's contents
directly is being there may be other things we may want to do besides
read() the whole thing at once.  Concretely, we might want to
progressively scan through the web site's contents without reading the
whole thing in one shot if we're concerned about memory consumption.  Or
we might just open the file and watch for an error, as a check to see that
the file exists on the web site.)
Yes.   This does make sense.

But is there something else that's bothering you?  Because we can't read
minds very well, you'll have to make up for our deficiency by telling us
what is surprising to you.  *grin*

Thanks.   Basically,  I had no idea how to interpret the value of urlopen
that python

And I had not yet found out about the read function, so even if I had
that urlopen returned a file ,   I still would not have know how to see the
of that file.

I will search for the read function in the tutorial.  What hints can you
give me for
finding it quickly in the tutorial?

Kermit     <   kermit at polaris.net  >

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20060323/a609dfff/attachment-0001.htm 

More information about the Tutor mailing list