["python","path","string-literals"]
How should I write a Windows path in a Python string literal?

Suppose I need to refer to the path C:\meshes\as. If I try writing that directly, like "C:\meshes\as", I encounter problems - either some exception, or the path just doesn't work. Is this because \ is acting as an escape character? How should I write the paths?
You can use always: 'C:/mydir' This works both in Linux and Windows. Another possibility is: 'C:\\mydir' If you have problems with some names you can also try raw string literals: r'C:\mydir' However, the best practice is to use the os.path module functions that always joins with the correct path separator (os.path.sep) for your OS: os.path.join(mydir, myfile) From python 3.4 you can also use the pathlib module. This is equivalent to the above: pathlib.Path(mydir, myfile) or: pathlib.Path(mydir) / myfile