0

I have a problem with passing windows path to a function in python. Now, if I hard code the path everything actually works. So, my code is:

from pymatbridge import Matlab
lab = Matlab(executable=r'"c:\Program Files \MATLAB\bin\matlab.exe"')
lab.start()

This works fine as I am using the raw string formatting to the hard-coded string. Now, the issue is that the string is passed as a variable. So, imagine I have a variable like:

path="c:\Program Files \MATLAB\bin\matlab.exe"

Now, I am unable to figure out how to get the equivalent raw string from this. I tried may things like shlex.quote(path) and this makes issue with the \b. Without conversion to the raw string, the space in Program Files causes a problem, I think.

Luca
  • 10,458
  • 24
  • 107
  • 234

1 Answers1

-1
def testpath(path):
    print path

testpath(path='c:\\Program Files \\MATLAB\\bin\\matlab.exe')

output is:

c:\Program Files \MATLAB\bin\matlab.exe

If you are facing issues with space between Program Files use Progra~1 instead

be_good_do_good
  • 4,311
  • 3
  • 28
  • 42