Trouble with generator

Boethius boethius at techie.com
Sat Jan 4 08:34:50 EST 2003


I'm getting a StopIteration exception with this generator:

--------------------------------------------------------
    def _linkGenerator(self, baseUrl):

        counter = 1
        maxPages = 4

        if baseUrl[0:7] == 'http://':
            url = baseUrl[7:]
        else:
            url = baseUrl

        
        if counter < maxPages:
            yield string.join(('http://www.google.com/search?q=link:',
                               url,
                               '&hl=es&lr=&ie=UTF-8&filter=0',
                               '&start=',
                               str((counter - 1) * 10)), '')
        else:
            yield None

        counter += 1
----------------------------------------------

When I call the next() method for the second time, I get this error:

>>> gen = g._linkGenerator( 'http://www.easyjob.net')
>>> gen.next()
'http://www.google.com/search?q=link:www.easyjob.net&hl=es&lr=&ie=UTF-8&filter=0&start=0'
>>> gen.next()
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
StopIteration

What am I doing wrong? O:-)

TIA




More information about the Python-list mailing list