Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
escape single quote
#1
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.
"Human history becomes more and more a race between education and catastrophe." - H. G. Wells (1866-1946)
Reply
#2
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\\'
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Warning - ' invalid escape sequence '\s'' tester_V 4 36,936 Aug-08-2024, 04:58 PM
Last Post: tester_V
  use of escape character in re.sub and find WJSwan 1 1,685 Feb-16-2023, 05:19 PM
Last Post: Larz60+
  python sql query single quote in a string mg24 1 2,322 Nov-18-2022, 08:01 PM
Last Post: deanhystad
  Escape indentation Frankduc 11 5,323 Jan-31-2022, 02:41 PM
Last Post: Frankduc
  add Escape charcters in string GrahamL 3 2,048 Jan-20-2022, 01:15 PM
Last Post: GrahamL
  Escape Single quotation between each content tag usman 3 3,850 May-02-2021, 03:32 PM
Last Post: snippsat
  DIY Escape Room for fun StannemanPython 1 4,393 Feb-17-2021, 10:53 PM
Last Post: maurom82
  How to escape OrderedDict as an argument? Mark17 2 2,807 Dec-23-2020, 06:47 PM
Last Post: Mark17
  How to double quote filenames (spaces)? Winfried 2 4,706 Jan-25-2020, 09:39 PM
Last Post: Winfried
  help for escape sequences NewPi 1 2,762 Dec-11-2019, 11:22 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020