Getting weird errors for python script on lines that don't exist

iHildy

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>
Mike67

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

ReactJS eslinting throwing errors on lines that don't exist

From Dev

Script went weird with 20 errors which don't make sense (unity)

From Dev

lineinfile: Don't insert lines if they already exist

From Dev

Getting messages from services that don't exist

From Dev

Install R on RedHat errors on dependencies that don't exist

From Dev

Find files that don't exist a specific regex in even lines

From Java

Why don't I get any syntax errors when I execute my Python script with Perl?

From Java

Python pathlib make directories if they don’t exist

From Java

xPath expression: Getting elements even if they don't exist

From Dev

Python strip() don't work for new lines

From Dev

Python BeautifulSoup "weird" errors

From Dev

Merging errors into my custom account_form is causing errors when properties don't exist

From Dev

Python Asyncio script don't finish

From Dev

Script in Python using subprocess don't work

From Dev

AngularJS and jsFiddle not working - getting weird errors

From Dev

Merge SPSS variables if they don't exist in the original file, using Python

From Dev

Print lines between start & end pattern, but if end pattern does not exist, don't print

From Dev

AWS Lambda Python reads all lines but don't write all

From Dev

records that exist in the database that don't exist in the list

From Dev

Why am I getting Invalid column name on field names that don't exist in my model?

From Dev

for loop on files that don't exist

From Dev

GGplot columns don't exist

From Dev

I am getting errors in my code and i don't know how to fix(Java fx stackPane)

From Dev

I don't understand these errors im getting with my on_member_join/on_member_remove functions

From Dev

SQL Server transactions and transaction isolation - getting errors that I don't know how to fix

From Dev

Using math.h for sin function and getting errors don't know why

From Dev

Trying to compile X Window System and getting errors that I don't know

From Dev

I'm getting errors that I don't understand installing NodeJS on a freshly installed Ubuntu that is otherwise blank

From Dev

I was getting 3 errors when following a tutorial and I don't know how to fix them

Related Related

  1. 1

    ReactJS eslinting throwing errors on lines that don't exist

  2. 2

    Script went weird with 20 errors which don't make sense (unity)

  3. 3

    lineinfile: Don't insert lines if they already exist

  4. 4

    Getting messages from services that don't exist

  5. 5

    Install R on RedHat errors on dependencies that don't exist

  6. 6

    Find files that don't exist a specific regex in even lines

  7. 7

    Why don't I get any syntax errors when I execute my Python script with Perl?

  8. 8

    Python pathlib make directories if they don’t exist

  9. 9

    xPath expression: Getting elements even if they don't exist

  10. 10

    Python strip() don't work for new lines

  11. 11

    Python BeautifulSoup "weird" errors

  12. 12

    Merging errors into my custom account_form is causing errors when properties don't exist

  13. 13

    Python Asyncio script don't finish

  14. 14

    Script in Python using subprocess don't work

  15. 15

    AngularJS and jsFiddle not working - getting weird errors

  16. 16

    Merge SPSS variables if they don't exist in the original file, using Python

  17. 17

    Print lines between start & end pattern, but if end pattern does not exist, don't print

  18. 18

    AWS Lambda Python reads all lines but don't write all

  19. 19

    records that exist in the database that don't exist in the list

  20. 20

    Why am I getting Invalid column name on field names that don't exist in my model?

  21. 21

    for loop on files that don't exist

  22. 22

    GGplot columns don't exist

  23. 23

    I am getting errors in my code and i don't know how to fix(Java fx stackPane)

  24. 24

    I don't understand these errors im getting with my on_member_join/on_member_remove functions

  25. 25

    SQL Server transactions and transaction isolation - getting errors that I don't know how to fix

  26. 26

    Using math.h for sin function and getting errors don't know why

  27. 27

    Trying to compile X Window System and getting errors that I don't know

  28. 28

    I'm getting errors that I don't understand installing NodeJS on a freshly installed Ubuntu that is otherwise blank

  29. 29

    I was getting 3 errors when following a tutorial and I don't know how to fix them

HotTag

Archive