urlopen.read()

K

ken

Hi,

When I call urlopen.read() like this:

data = urlopen("http://localhost").read().

Does that mean I will read the whole document to data, regardless how
many data being sent back?

Thank you.
 
S

Steve Holden

ken said:
Hi,

When I call urlopen.read() like this:

data = urlopen("http://localhost").read().

Does that mean I will read the whole document to data, regardless how
many data being sent back?

Thank you.
Yes. However you can read (and presumably process)one line at a time
with readline() or by iterating over the object returned by urlopen().

I'd recommend trying something like:

u = urlopen("http://localghost/")
for line in u:
print line # or process it some other way

or

line = u.readline()
while line:
# process the line
line = u.readline()

There is no need to buffer the whole content before you process it
unless you choose to do so.

regards
Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top