I wrote this script a while ago that will search the definition of all words in a searches.txt file, it was used for school vocabulary projects. With the start of the new school year, I needed to recover it to use it again. I'm getting weird errors that seem like its a problem with my python install but I get nothing similar to it in other py programs, I might also not have a library installed. The code and the errors are below, let me know what you think the problem is. Thanks in advance!
Code
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 example
Matter
Energy
Temperature
Non-Newtonian Liquid
Sublimation
Deposition
WINDOWS ERROR
['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
ary.com/browse/Crystallization', 'https://www.dictionary.com/browse/Centrifugation', 'https://www.dictionary.com/browse/
Distillation', 'https://www.dictionary.com/browse/Chromatography', 'https://www.dictionary.com/browse/Filtration', 'http
s://www.dictionary.com/browse/Homogeneous', 'https://www.dictionary.com/browse/Heterogeneous']
Traceback (most recent call last):
File "C:\Users\TestoW\Documents\Coding\definition-search\AutoLookUp.py", line 26, in <module>
call(["open"]+links)
File "C:\Python38\lib\subprocess.py", line 340, in call
with Popen(*popenargs, **kwargs) as p:
File "C:\Python38\lib\subprocess.py", line 854, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Python38\lib\subprocess.py", line 1307, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified
C:\Users\TestoW>
This code works for me to open the links in the list:
for lnk in links:
call(["start"]+[lnk], shell=True)
-- Update --
Found another way to open the links without opening a cmd window.
import win32com.client
sh = win32com.client.Dispatch('WScript.Shell')
for lnk in links:
sh.run(lnk)
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments