2

I tried to add a directory path to sys.path, but it gives me an error:

import sys
sys.path.append("C:\Users\tamer\Desktop\code\python\modules")
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
Alexander L. Hayes
  • 3,892
  • 4
  • 13
  • 34
  • Does this answer your question? [Windows path in Python](https://stackoverflow.com/questions/2953834/windows-path-in-python) – sahasrara62 Dec 03 '22 at 18:11

2 Answers2

0

This should do it:

sys.path.append("C:\\Users\\tamer\\Desktop\\code\\python\\modules")

Cow
  • 2,543
  • 4
  • 13
  • 25
0

Another approach is to use raw string, basically r is prefixed. For this use case it should be.

sys.path.append(r"C:\Users\tamer\Desktop\code\python\modules")
Yaman Jain
  • 1,254
  • 11
  • 16