May-03-2021, 07:51 PM
I am a beginner at python coding.
I wrote a simple code that lists a number of programs and asks the user to choose one of the programs. It will then open a website with the version history of that program, and, where it exists, run the updater of the program.
Initially I wrote the program manually writing out the list of programs (20) and then manually write out the url and, where relevant, the path and file name to the updater. Something like:
Then I tried to write the code where the list of programs and the url and file paths are listed in a .csv file. The values for the url and prg variables are read from the .csv file (using numpy load.txt)
However:
In the original (long-winded)code I manually set the full file name for Chrome:
In the updated code the same full file name is read into prg, but this time
In the new code
Any suggestions what I am doing wrong?
I use Windows
I wrote a simple code that lists a number of programs and asks the user to choose one of the programs. It will then open a website with the version history of that program, and, where it exists, run the updater of the program.
Initially I wrote the program manually writing out the list of programs (20) and then manually write out the url and, where relevant, the path and file name to the updater. Something like:
if choice == 1 url = 'https://blablabla' prg = 'C:\\Program Files\\blablabla'After manually defining the URL and prg variables for all 20 options, I run:
webbrowser.open_new_tab(url) subprocess.Popen(prg)This works fine.
Then I tried to write the code where the list of programs and the url and file paths are listed in a .csv file. The values for the url and prg variables are read from the .csv file (using numpy load.txt)
webbrowser.open_new_tab(url)works fine
However:
subprocess.Popen(prg)gives an error message if the file path has a blank space in it (which is in 19 out of the 20 options). The error message is:
Error:Traceback (most recent call last):
File "test.py", line 32, in <module>
mainmenu()
File "test.py", line 30, in mainmenu
subprocess.Popen(prg)
File "C:\Users\zorin\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 858, in _init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Users\zorin\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 1311, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified
One example:In the original (long-winded)code I manually set the full file name for Chrome:
prg = 'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe'and
subprocess.Popen(prg)runs Chrome without a problem.
In the updated code the same full file name is read into prg, but this time
subprocess.Popen(prg)gives the above-mentioned error code (if the file path has a black space it).
In the new code
print(prg)will give:
Output:C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe
so the correct value is read into the variable.Any suggestions what I am doing wrong?
I use Windows