how to judge urllib.Request is finished?
Marc 'BlackJack' Rintsch
bj_666 at gmx.net
Tue Jul 1 05:10:06 EDT 2008
On Tue, 01 Jul 2008 15:16:03 +0800, oyster wrote:
> currently I am using
> [code]
> req=urllib2.Request(url)
> data=''
> if '</htm>' not in data:
> fd=urllib2.urlopen(req)
> data=fd.read()
> time.sleep(10)
> time.sleep(10)
> blahblah
> [/code]
That looks very strange. Why the ``if`` and the `sleep()`\s? The ``if``
condition is always true, so it's completely unnecessary. The `read()`
call is blocking, that means it returns iff the complete data is read. So
there's no need to wait or to check if all is read. If there's a problem
with the connection an exception should be raised by `urllib2`.
Ciao,
Marc 'BlackJack' Rintsch
More information about the Python-list
mailing list