我不久前编写了这个脚本,它将搜索 searchs.txt 文件中所有单词的定义,它用于学校词汇项目。随着新学年的开始,我需要恢复它才能再次使用它。我遇到了奇怪的错误,看起来像是我的 python 安装的问题,但在其他 py 程序中我没有得到任何类似的错误,我可能也没有安装库。代码和错误如下,让我知道您认为问题是什么。提前致谢!
代码
from subprocess import call
import re
import sys
links = []
filename = 'C:\\Users\\TestoW\\Documents\\Coding\\definition-search\\searches.txt'
try:
with open(filename) as linkListFile:
for line in linkListFile:
link = line.strip()
if link != '':
if re.match('http://.+|https://.+|ftp://.+|file://.+', link.lower()):
links.append(link)
else:
links.append('https://www.dictionary.com/browse/' + link)
#https://www.google.com/search?q=
#https://www.dictionary.com/browse/
#http://maps.google.com/?q=
except IOError:
print ('Failed to open the file "%s".\nExiting.')
sys.exit()
print (links)
call(["open"]+links)
seaches.txt 示例
Matter
Energy
Temperature
Non-Newtonian Liquid
Sublimation
Deposition
窗口错误
['https://www.dictionary.com/browse/Matter', 'https://www.dictionary.com/browse/Energy', 'https://www.dictionary.com/bro
wse/Temperature', 'https://www.dictionary.com/browse/Non-Newtonian Liquid', 'https://www.dictionary.com/browse/Sublimati
on', 'https://www.dictionary.com/browse/Deposition', 'https://www.dictionary.com/browse/Melting Point', 'https://www.dic
tionary.com/browse/Boiling Point', 'https://www.dictionary.com/browse/Phase Change', 'https://www.dictionary.com/browse/
Endothermic', 'https://www.dictionary.com/browse/Exothermic', 'https://www.dictionary.com/browse/Compound', 'https://www
.dictionary.com/browse/Intrinsic Property', 'https://www.dictionary.com/browse/Extrinsic Property', 'https://www.diction
温温酱
相关分类