我试图向sys.path添加一个目录路径,但是它给了我一个错误:
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发布于 2022-12-03 14:52:36
这应该可以做到:
sys.path.append("C:\\Users\\tamer\\Desktop\\code\\python\\modules")
发布于 2022-12-03 18:11:21
另一种方法是使用raw string,基本上r是前缀。对于这个用例,应该是这样的。
sys.path.append(r"C:\Users\tamer\Desktop\code\python\modules")https://stackoverflow.com/questions/74667805
复制相似问题