1
path = r'C:\Program Files\1\1.exe'

I can run a program using the path above. I don't want to hardcode it, so I'm trying to use a variable in place of the 1s. This is what I came up with:

variable1 = '1'
path = r'C:\Program Files\ , +variable1 , +\, +variable1, +.exe'

This doesn't work. How do I make it work?

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
Arad016
  • 53
  • 8
  • Use `os.path.join()`. And either use `/` or raw strings, otherwise the backslash starts escape sequences. – Barmar May 11 '20 at 16:30

1 Answers1

0
variable1 = '1'

path = 'C:\\Program Files\\'+variable1+'\\'+variable1+'.exe'

\ is special char so you need to escape it with another \

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
Sami Fakhfakh
  • 89
  • 2
  • 17