1

In Windows, when using pathlib, is there a way to output the path with a double back slash?

from pathlib import Path

working_directory = Path(r'C:\Downloads')
print(working_directory)

output is C:\Downloads\temp

How do I make the output a double back slash, such as: C:\\Downloads\\temp

2
  • Any particular reason you want to do that? Your path object is correct and usable as is. Commented Jan 26, 2019 at 9:12
  • I need to output to a csv, as the interfacing mailmerge file requires a file path with a double slash. Commented Jan 28, 2019 at 10:29

1 Answer 1

3

Just use %r:

from pathlib import Path

working_directory = Path(r'C:\Downloads')
print('%r'%str(working_directory))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.