2
file_path =('C:\\Users\\zlq\Desktop\\python_crash_course\\书籍资料
\\chapter_10\\pi_digits.txt')
with open(file_path) as file_object:
contents = file_object.read()
print(contents)

As I open file above in python 3, the path is too long and I want to break it two lines. But I tried several ways like adding""" , they won't work. So how do I break the path into two lines?

ZHU LQ
  • 21
  • 1
  • I've marked this as a dup, as I think just doing `'C:\\Users\\zlq\Desktop\\python_crash_course\\书籍资料' '\\chapter_10\\pi_digits.txt'` meets the requirements and is nice and clear, and can be split into two or more lines easily. [See here](https://docs.python.org/2.0/ref/string-catenation.html). – Ken Y-N Nov 15 '17 at 05:47
  • `'''C:\\Users\\zlq\Desktop\\python_crash_course\\书籍资料 \\chapter_10\\pi_digits.txt'''` should work as well... – l'L'l Nov 15 '17 at 05:48
  • BTW, I just noticed that there is only one backslash before `Desktop` - using forward slashes instead avoids the problem of forgetting to double up. – Ken Y-N Nov 15 '17 at 05:51
  • @KenY-N: Python is usually good about adding another one if it's a single `\ ` – l'L'l Nov 15 '17 at 05:52

0 Answers0