我编写了python代码,其中我已经为变量“emailentry”分配了一个字符串值。我现在要做的是在我的文本文件的最后一行“wattpad.txt”中添加这个字符串值。
我写了这段代码
with open("C:\Users\BRS\Desktop\wattpad.txt", 'a') as outfile:
outfile.write(emailentry /n)并得到错误
File "C:\Users\BRS\Desktop\wattpad acc maker.py", line 41
with open("C:\Users\BRS\Desktop\wattpad.txt", 'a') as outfile:
^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape请帮助在0.2秒内完成
发布于 2020-06-12 08:04:07
\U是字符串符号中转义序列的开始,其他几个,\u,\n.
如果要在字符串中使用litteral反斜杠,可以:
"C:\\Users\\BRS\\Desktop\\wattpad.txt"rr"C:\Users\BRS\Desktop\wattpad.txt"作为字符串的前缀来使用原始字符串。"C:/Users/BRS/Desktop/wattpad.txt"https://stackoverflow.com/questions/62339837
复制相似问题