Python cannot start a file
Question:
os.startfile either gives "UnicodeError" or "FileNotFoundError". How to fix this?
I also used a "Try Except" in UnicodeError, but still UnicodeError.
I used this code:
import os
os.startfile("C:\Users\Me\AppData\Local\Microsoft\Windows\WinX\Group2\Run.lnk")
I expected that Run (Windows + R) should open
I got a "FileNotFoundError".
I checked the file in location and it was there. I tried forwarding the slashes and the problem still persists.
Answers:
Use r
:
import os
os.startfile(r"C:UsersMeAppDataLocalMicrosoftWindowsWinXGroup2Run.lnk")
os.startfile either gives "UnicodeError" or "FileNotFoundError". How to fix this?
I also used a "Try Except" in UnicodeError, but still UnicodeError.
I used this code:
import os
os.startfile("C:\Users\Me\AppData\Local\Microsoft\Windows\WinX\Group2\Run.lnk")
I expected that Run (Windows + R) should open
I got a "FileNotFoundError".
I checked the file in location and it was there. I tried forwarding the slashes and the problem still persists.
Use r
:
import os
os.startfile(r"C:UsersMeAppDataLocalMicrosoftWindowsWinXGroup2Run.lnk")