1

I'm trying to make a program that will launch programs for me, but some programs python just won't find. I've been using the technique of:

if action == "Powerpoint":
    import os
    os.startfile("C:\Program Files (x86)\Microsoft Office\root\Office16\POWERPNT.exe")

And this has worked for all of my other programs but this one just doesn't work.

ThisSuitIsBlackNot
  • 23,492
  • 9
  • 63
  • 110
Dillchips
  • 13
  • 3

1 Answers1

1

Backslashes in string literals are special:

[String literals] can be enclosed in matching single quotes (') or double quotes (")...The backslash (\) character is used to escape characters that otherwise have a special meaning, such as newline, backslash itself, or the quote character.

The \r in your string:

"C:\Program Files (x86)\Microsoft Office\root\Office16\POWERPNT.exe"
                                        ^^

is being interpreted as an escape sequence meaning carriage return, not a literal backslash followed by a literal "r".

You should use a raw string so backslashes aren't interpreted as escape sequences:

r"C:\Program Files (x86)\Microsoft Office\root\Office16\POWERPNT.exe"
ThisSuitIsBlackNot
  • 23,492
  • 9
  • 63
  • 110