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.

Asked By: Gorzan

||

Answers:

Use r:

import os
os.startfile(r"C:UsersMeAppDataLocalMicrosoftWindowsWinXGroup2Run.lnk")

Answered By: Avión
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.