Trouble with seek(0) command

Randy Gamage randy at gamages.com
Fri Nov 7 17:09:57 EST 2003


I can't figure out why this script gets an error.  This is script that gets
a web page, then parses the title out of the web page.  When it's done
parsing, I would like to reset the pointer to the beginnning of the response
file object, but the seek(0) command does not work.  Anybody know why?

The error message says: AttributeError: addinfourl instance has no attribute
'seek'

But in PythonWin IDE, when I type response and then a ".", the popup options
include both read and seek.  What's going on?
Here's the code:

#!/usr/bin/python
import urllib2, string

def Title(response):
    # Returns the title of a web page
    page = response.read()
    page = page[string.find(page,'<title>'):string.find(page,'</title>')]
    page = page[string.find(page,'>')+1:]
    response.seek(0)  # This causes an error - WHY?
    return page

strurl = 'http://www.gamatronix.com'
resp = urllib2.urlopen(strurl)
print Title(resp)
print resp.read()  # Without the seek command, this will return nothing,
because the pointer is at the end

Please copy me on responses.

Thanks,
Randy






More information about the Python-list mailing list