-1
我試圖追加全球列表變量與新詞在try /除了例外,但嘗試/除了我得到空列表。如何在try/except exception中附加全局列表變量?
list = [] # created empty list with global scope
def try_multiple_operations(j):
try:
jopen = urllib2.urlopen(j) # opened url for parsing content
versions = jopen.read() # read and save to variable
version = pq(versions) # filtering content with pyquery
.... # pyquery operations
list.append(version)
except urllib2.URLError: # urllib2 exception
list.append('0.0')
except urllib2.HTTPError: # urllib2 exception
list.append('0.0')
executor = concurrent.futures.ProcessPoolExecutor(5)
futures = [executor.submit(try_multiple_operations, j) for j in list]
concurrent.futures.wait(futures)
print len(list) # 0 elements
最後我得到了空白列表。如何在try/except中添加/附加新結果到全局列表?
? – user2357112
嘗試運行該功能。 – kmad1729
對不起,我更新了代碼。我已經嘗試過但沒有變化。 – user2993877