From: Danny Yoo
Date: 03/23/06 00:08:25
Subject: Re: [Tutor] urlopen: where are the results?
 
  
We can use 'import urllib2', or if we really want urlopen():
 
######
from urllib2 import urlopen
######
 
****
Thanks.
****
 
 
> >>> 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 information
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
returned.
 
And I had not yet found out about the read function, so even if I had understood
that urlopen returned a file ,   I still would not have know how to see the contents
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     <   [EMAIL PROTECTED]  >
 
 
 
 
 
 
 
 
 
 
_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to