简体   繁体   English

试图从命令行运行Python脚本时,截断的unicode转义

[英]Truncated unicode escape trying to run a Python script from the command line

Whenever I access a cmd window and after type in 'python' and then try to access a python file, I get the error, 每当我访问cmd窗口并在键入“ python”后尝试访问python文件时,都会收到错误消息,

SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape.

I am really puzzled by this; 我真的对此感到困惑; I try to run a python file by typing the file path inside of quotations, and I have also tried putting the r before the path. 我尝试通过在引号内键入文件路径来运行python文件,并且我还尝试将r放在路径前。 I have also tried doubling the slashes, but that only results in the window regurgitating the path. 我还尝试过将斜杠加倍,但这只会导致窗口重新显示路径。

Can you be a little bit more specific? 您能更具体一点吗?

If you are using python 2.7 and your file contains unicode it needs to inform the interpreter about that by a coding comment at the beginning of the file 如果您使用的是python 2.7,并且您的文件包含unicode,则需要在文件开头通过编码注释将其告知解释器

# -*- coding: utf-8 -*-

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM