Python Forum
escape single quote - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: escape single quote (/thread-21015.html)



escape single quote - deep_logic - Sep-10-2019

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.


RE: escape single quote - SheeppOSU - Sep-10-2019

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\\'