0

new = "file.txt"

source_path = r"C:\Users\Shri Krishan\Documents" + "\" + new

print(source_path)

Error: SyntaxError: EOL while scanning string literal

krissh6563
  • 11
  • 2
  • 1
    To work with file and directory paths, I suggest using [`os.path`](https://docs.python.org/3/library/os.path.html) or the more recent [`pathlib`](https://docs.python.org/3/library/pathlib.html) instead of using string concatenation. – albert May 18 '21 at 06:58

1 Answers1

0

code:

new = "file.txt"

source_path = r"C:\Users\Shri Krishan\Documents" + "\\" + new

print(source_path)

result:

C:\Users\Shri Krishan\Documents\file.txt
leaf_yakitori
  • 2,232
  • 1
  • 9
  • 21
  • 1
    A bit of explanation would be nice. Also why concatenate two string literals? You could've simply written `r"C:\Users\Shri Krishan\Documents\" + new`. – Selcuk May 18 '21 at 06:58