Python 2.7 Python中带换行符的升华文本注释?

Python 2.7 Python中带换行符的升华文本注释?,python-2.7,comments,sublimetext3,Python 2.7,Comments,Sublimetext3,我注意到,如果我在Sublime Text 3中用注释将一长行Python分开,它会将前两行标记为红色,因此是错误的,尽管脚本运行良好 # This is a long line broken up with comments "So I'm ready to attack, gonna lead the pack," + \ # red comment here "Gonna get a touchdown, gonna take you out," + \ # and here "That

我注意到,如果我在Sublime Text 3中用注释将一长行Python分开,它会将前两行标记为红色,因此是错误的,尽管脚本运行良好

# This is a long line broken up with comments 
"So I'm ready to attack, gonna lead the pack," + \ # red comment here
"Gonna get a touchdown, gonna take you out," + \ # and here
"That's right, put your pom-poms down, getting everybody fired up" # ok here
我是否必须使用正则表达式修改Python的Sublime配置文件(以我当前的语法样式)来修复此问题?

有这样一句话:

以反斜杠结尾的行不能包含注释。反斜杠不会继续注释。反斜杠不会延续除字符串文字以外的标记,即不能使用反斜杠在物理行上拆分字符串文字以外的标记。反斜杠在字符串文字以外的行的其他位置是非法的

实际上,对于Python 2和Python 3,您发布的代码都被视为无效,并会生成错误:

  File "/home/tmartin/test.py", line 2
    x = "So I'm ready to attack, gonna lead the pack," +  # red comment here
                                                                           ^
SyntaxError: invalid syntax
在中执行此操作将提供更具体的错误消息:

Python 3.6.0 (default, Jan 13 2017, 00:00:00) 
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> "So I'm ready to attack, gonna lead the pack," + \ # red comment here
  File "<stdin>", line 1
    "So I'm ready to attack, gonna lead the pack," + \ # red comment here
                                                                        ^
SyntaxError: unexpected character after line continuation character
因此,Sublime告诉您在这种情况下代码无效似乎是正确的,并且我无法在没有修改版本的Python解释器的情况下让您的代码片段保持不变,尽管我绝不是Python专家

这就是说,假设这确实适用于您,阻止升华将这些行显示为错误的唯一方法是手动编辑升华附带的Python语法,使其不会将这种情况视为无效