在gdic中我有3个键(1,2,3)和值。在页面I中有两个等于两个键(1,3)。为什么pdic只添加一个值? “lol”打印两次,但必须打印一次,是吗?进度条无法正常工作。
length = len(self._gdic)
count = 1.0
count2 = 1
pbar = ProgressBar().start()
for k in self.gdic.keys():
for i in page:
if (k == i[0].decode('utf-8')):
pdic[i[0]] = i[2].lower()
percent_done = count / length
percent_done = round(percent_done * 100)
pbar.update(percent_done)
count += 1.0
count2 = 1
break
elif (count2 == length):
percent_done = count / length
percent_done = round(percent_done * 100)
pbar.update(percent_done)
count += 1.0
count2 = 1
print("lol")
break
else:
count2 += 1
continue
pbar.finish()
编辑:好的,我可能找到了解决方案。
length = len(page)
length2 = len(self.gdic)
count = 1.0
count2 = 1
pbar = ProgressBar().start()
for k in self.gdic.keys():
for i in page:
if (k == i[0].decode('utf-8')):
pdic[i[0]] = i[2].lower()
percent_done = count / length2
percent_done = round(percent_done * 100)
print("ss")
print k
pbar.update(percent_done)
count += 1.0
count2 = 1
break
else:
if (count2 == length):
percent_done = count / length2
percent_done = round(percent_done * 100)
print("lol")
print k
pbar.update(percent_done)
count += 1.0
count2 = 1
continue
count2 += 1
pbar.finish()
页面的长度(dict)可以与 gdic(dict)的长度不同。如果我们在页面中找到了 k ,则进度条正在更新, count2 正在设置为默认值。如果 k 不在页面中,我们必须检查 count2 和长度(页面)值。如果它们相同,我们会更新进度条并将 count2 设置为默认值。如果它们不相同,我们会增加 count2 。我正在使用打印来检查此解决方案的工作情况。