2016-09-27 19 views
0

我想將一個列表放入我的線程腳本中,但是我面臨一個問題。Python - 在線程模塊中添加一個列表

列表文件(例如)內容:

http://google.com 
http://yahoo.com 
http://bing.com 
http://python.org 

我的腳本:

import codecs 
import threading 
import sys 
import requests 
from time import time as timer 
from timeout import timeout 
import time 

try: 
    with codecs.open(sys.argv[1], mode='r', encoding='ascii', errors='ignore') as iiz: 
     iiz=iiz.read().splitlines() 
except IOError: 
    pass 

oz = list(iiz) 
def nnn(url): 
    hzz = {'param1': sys.argv[2], 'param2': sys.argv[3]} 
    po = requests.post(url,data=hzz) 
    if po: 
      print("ok \n") 

if __name__ == '__main__': 
    threads = [] 
    for i in range(1): 
     t = threading.Thread(target=nnn, args=(oz,)) 
     threads.append(t) 
     t.start() 

回答

0

能否請您澄清一下詳細說明你想實現什麼。

我猜你想申請的網址加載到一個Web瀏覽器或終端...

而且你不應該需要把網址進入,因爲當你打開一個列表該文件包含網址,它會自動將其分類到一個列表中。換句話說,iiz中的內容已經是列表格式。我個人並沒有在你使用的模塊(除時間之外)上工作太多,但我會盡我所能來幫助你,希望其他用戶也會嘗試和幫助你。

+0

感謝您的回答,我想通過多線程發送郵件請求到一個位置列表 – Angel

+0

嗨天使,我剛剛注意到您的腳本正在嘗試搜索多個文件,這是您的意圖嗎? –

+0

所以,只是爲了澄清,你想發送發佈數據來搜索這些網站上的內容? –