0

I am receiving the following error while trying to execute a python script from my C# application. I assume it is having problems with the colon in the filePath, collected when a users selects their file.

How do I execute the script (with arguments) without throwing the exception

enter image description here

0

1 Answer 1

2

Quoting values to put them into generated code can be tricky to get your head around.

The string you're building to execute doesn't quote the filename string in the Python code. The Python interpreter is seeing:

x = C:\blah\blah + profile-value

So it's complaining about the colon. It needs to see:

x = r'C:\blah\blah' + r'profile-value'

So the C# should be something like:

py.Execute("x = r'" + filePath + "' + r'" + profile + "'", s);

It probably makes more sense to just do the full path construction in C# and simplify the Python string you're building, although maybe that's because the code you're posting about is a simplification of the real problem.

1
  • That worked, as soon as I am able, I will mark as answer. Thank you!
    – Chris
    Commented Dec 17, 2014 at 15:18

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.