import subprocess
subprocess.Popen('C:\Users\user\Desktop\notepad.lnk')
gives an error
Error:
C:\Python36\kodovi>times.py
File "C:\Python36\kodovi\times.py", line 88
subprocess.Popen('C:\Users\user\Desktop\notepad.lnk')
^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in positio
n 2-3: truncated \UXXXXXXXX escape
I'm trying to open a notepad but it gives error that I don't understand.
Backslashes indicate special characters. \U indicates a unicode character. That's causing your error. Either double the backslashes ('C:\\Users...') or make it a raw string (r'C:\Users...') which will ignore backslash encodings.
Thank you, now I got this one
Error:
C:\Python36\kodovi>times.py
Traceback (most recent call last):
File "C:\Python36\kodovi\times.py", line 88, in <module>
subprocess.Popen(r'C:\Users\user\Desktop\notepad.lnk')
File "C:\Python36\lib\subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "C:\Python36\lib\subprocess.py", line 997, in _execute_child
startupinfo)
OSError: [WinError 193] %1 is not a valid Win32 application
how everything looks simple in the book but complicated when you have to make it work.
That one I don't know, I am not familiar with the subprocess module.
For those who are interested in this topic the correct code should be:
subprocess.Popen(r'C:\Users\user\Desktop\notepad.lnk', shell=True)
Shortcuts are not recognized by subprocess as an application.