Yes, \ in Python string literals indicate the start of an escape sequence. On your way, you have a valid two-character \a escape sequence that collapses into a single character, which is ASCII Bell :
>>> '\a' '\x07' >>> len('\a') 1 >>> 'C:\meshes\as' 'C:\\meshes\x07s' >>> print('C:\meshes\as') C:\meshess
Other common escape sequences include \t (tab), \n (string), \r (carriage return):
>>> list('C:\test') ['C', ':', '\t', 'e', 's', 't'] >>> list('C:\nest') ['C', ':', '\n', 'e', 's', 't'] >>> list('C:\rest') ['C', ':', '\r', 'e', 's', 't']
As you can see, in all of these examples, the backslash and the next character in the literal were grouped together to form a single character in the last line. A complete list of escape sequences, Python is here .
There are many ways to deal with this:
Python will not process escape sequences in string literals prefixed with r or R :
>>> r'C:\meshes\as' 'C:\\meshes\\as' >>> print(r'C:\meshes\as') C:\meshes\as
Python on Windows should also handle slashes.
You can use os.path.join ...
>>> import os >>> os.path.join('C:', os.sep, 'meshes', 'as') 'C:\\meshes\\as'
... or the new pathlib module
>>> from pathlib import Path >>> Path('C:', '/', 'meshes', 'as') WindowsPath('C:/meshes/as')
vaultah Mar 31 '18 at 12:31 2018-03-31 12:31
source share