我有这个密码:def merge_new_old_urls(urls_list, urls_file_path):
url_dict = {}
try:
with open(urls_file_path, "r") as f:
data = f.readlines()
for line in data:
#read what is already in file
url_dict = { line.split()[0]: int(line.split()[1])}
for new in urls_list:
for key in url_dict.keys():
if new == key:
print 'found'
url_dict[key] += 1
else:
url_dict[new] = 1
except IOError:
logging.critical('no files to read from %s' % urls_file_path)
raise IOError('no files to read from %s' % urls_file_path)
return url_dict
这应该从文件中读取数据,并将其与新的数据列表合并,计算重复的次数。包含旧URL的文件如下所示:http://aaa.com 1
http://bbb.com 2
http://ccc.com 1'http://aaa.com':2
'http://bbb.com':3
'http://ccc.com':1
但我的代码不能正常工作。有人能治好吗?你知道吗