Filepath problem

Hi

Python seems to translate the filepath into some cryptic characters, see here:


Does anybody know what I do wrong ?

Kind regards
Alain

I think this is because some of the back slashes are interpreted as special characters. A quick solution might be to make the string ‘raw’ (prepend an ‘r’ in front of the first quote, then it won’t interpret the backslashes) like:

path = r"c:\a\b\c"

or you can use forward slashes (which will even work on windows)

path = “c:/a/b/c”

I don’t know if putting r in front of the string does something.

Inside a string the slash character </b> is considered an escape character, so in combination with another character you get some special results.
e.g.


	 is a tab
\r is a return character

 is a new line character
\s sometimes considered a space

Now the point of interest is that if you want a string to contain some special characters (like slash, double quote) and store them exactly as they are (without any special operation) then you will have to escape these characters.

e.g.


If you want to escape the slash character in use a path use double slash (alternatively use backslash as varken suggested)
path = "c:\\a\\b\\c"

If you want to escape the double quote character
phrase = "And he said: \"Howdy Mate!!!\""

I don’t know if these make sense, for more information you can google about escape characters. :slight_smile:

Thank you guys.
I found another solution for my case.

All I actually needed was the Users Script Path, and I do that by reading that Value directly from Blender without typing the hole Path by hand :slight_smile:

But I’ll take your answers into my personal FAQ :wink:

Kind regards
Alain

I am pretty sure it does :slight_smile: check