Python Forum

Full Version: escape single quote
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi all,
I'm trying to do a simple chdir in IDLE, 2.7.5.

os.chdir(r'\\hilltop3\users$\LongRandy\My Documents\HOW-TO\'S)
I keep getting, "The system cannot find the path specified: "\\\\hilltop3\\users$\\LongRandy\\My Documents\\HOW-TO\\'s"

I did use the "\" single backslash just to try it and it does work if I'm just printing something.

Not sure what I'm getting wrong.

Any help is appreciated.
For this type of stuff, it's best to use os's path.join. Example:
import os

textDoc = os.path.join('C:', 'users', 'user1', 'desktop', 'stuff', 'test.txt')

I you want to use single quotes you can do the following:
path = r'C:\users\user1\desktop\\'