这对我来说不是一个新问题.从C到PERL再到Windows Mobile,Windows XP和其他Windows版本的Python,这个问题仍然存在,让我很紧张.
现在在我的最新脚本中它再次发生.更具体一点:我用Python编写了一个简单的脚本.现在,当从调试器运行时,脚本正确地写入文件,但是在调试器之外它无法正常工作.它应该在写入时不写入文件.我使用python 2.6与eclipse和pydev.
这是代码
import httplib2
import thread
ht = httplib2.Http();
list = []
k = 0
def check(proxy, port):
global list
global k
try:
head = ht.request(proxy, 'HEAD')
except:
return
k = k + 1
list.append(proxy)
list.append(port)
def OnListCaller(ProxyList, OutFile, NListLen):
global list
global k
filei = open(ProxyList, 'r')
fileo = open(OutFile, 'a')
while 1:
proxy = filei.readline()
if not proxy: continue
port = filei.readline()
proxy = proxy.rstrip()
port = port.rstrip()
thread.start_new(check, (proxy, port,))
if k >= NListLen:
for t in list:
fileo.write(t + "\n")
list = []
fileo.close()
fileo = open(OutFile, 'a')
k = 0
OnListCaller('C:\proxy\input.txt', 'C:\proxy\checked.txt', 1)
Run Code Online (Sandbox Code Playgroud)
问题出现在if> k> = NListLen的OnListCaller中.当k>> =然后给定值时,应更新该文件.谢谢大家.
| 归档时间: |
|
| 查看次数: |
6776 次 |
| 最近记录: |