urlopen.read()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ken

    #1

    urlopen.read()

    Hi,

    When I call urlopen.read() like this:

    data = urlopen("http://localhost").rea d().

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

    Thank you.

  • Steve Holden

    #2
    Re: urlopen.read()

    ken wrote:
    Hi,
    >
    When I call urlopen.read() like this:
    >
    data = urlopen("http://localhost").rea d().
    >
    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
    --
    Steve Holden +44 150 684 7255 +1 800 494 3119
    Holden Web LLC/Ltd http://www.holdenweb.com
    Skype: holdenweb http://del.icio.us/steve.holden
    Recent Ramblings http://holdenweb.blogspot.com

    Comment

    Working...