0
當我在官方文檔,see this example:如何理解這個表達式: 「future_to_url = {executor.submit(load_url,網址,60):URL對於URL」
urls = ['http://www.foxnews.com/',
'http://www.cnn.com/',
'http://europe.wsj.com/',
'http://www.bbc.co.uk/',
'http://some-made-up-domain.com/']
def load_url(url, timeout):
with urllib.request.urlopen(url, timeout=timeout) as conn:
return conn.read()
with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor:
future_to_url = {executor.submit(load_url, url, 60): url for url in urls}
for future in concurrent.futures.as_completed(future_to_url):
url = future_to_url[future]
try:
data = future.result()
except Exception as exc:
print('%r generated an exception: %s' % (url, exc))
else:
print('%r page is %d bytes' % (url, len(data)))
不過,我不噸understant表達的含義是:
「future_to_url = {executor.submit(load_url,網址,60):URL對於URL」
是它從該語法點?謝謝!
謝謝,明白吧。 – Devin
不客氣! @Devin。 – zhenguoli