新人求指导,请问这个python代码为什么运行不了。
···f = open('C:/Users/Administrator/Desktop/yingwen.txt',"r")
all_words = []
for s in f.readlines():
s = s.replace(","," ").replace("."," ").lower()
all_words.extend(s.split(" "))
all_words = list(set(all_words))
all_words.sort()
f2 = open('C:\Users\Administrator\Desktop\ying.txt','w')
f2.write("\n".join(all_words))
f2.close()
···
主要实现的功能是讲一本英文小说的文章全部采集成单次罗列到一个新的txt文章里。但是怎么运行都是错误。错误内容是:
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "c:\Users\Administrator\.vscode\extensions\ms-python.python-2023.4.1\pythonFiles\lib\python\debugpy\__main__.py", line 39, in <module>
cli.main()
File "c:\Users\Administrator\.vscode\extensions\ms-python.python-2023.4.1\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 430, in main
run()
File "c:\Users\Administrator\.vscode\extensions\ms-python.python-2023.4.1\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 284, in run_file
runpy.run_path(target, run_name="__main__")
File "c:\Users\Administrator\.vscode\extensions\ms-python.python-2023.4.1\pythonFiles\lib\python\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line
320, in run_path
code, fname = _get_code_from_file(run_name, path_name)
File "c:\Users\Administrator\.vscode\extensions\ms-python.python-2023.4.1\pythonFiles\lib\python\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line
294, in _get_code_from_file
code = compile(f.read(), fname, 'exec')
File "c:\Users\Administrator\Desktop\胡\python\523.py", line 9
f2 = open('C:\Users\Administrator\Desktop\ying.txt','w')
^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape