Python:多行格式输出中的空格

Python:多行格式输出中的空格,python,pep8,Python,Pep8,试图通过pep8重新计算代码的系数 代码: print """Exception when sending email to: {0}, from: {1}, subject: {2}, e: {3}""".format(to, fr, subject, e) 输出: Exception when sending email to: to, from: fr, subject: subject, e: Invalid URL 'http/

试图通过pep8重新计算代码的系数

代码:

    print """Exception when sending email to: {0},
        from: {1}, subject: {2}, e: {3}""".format(to, fr, subject, e)
输出:

Exception when sending email to: to,
                from: fr, subject: subject, e: Invalid URL 'http//127.0.0.1:8000/'
如何从上述输出中的中删除
之前的空格?谢谢

更新

以下代码工作正常。我应该删除这个帖子吗

 34             print ($
 35                 "Exception when sending email to: {0},"$
 36                 "from: {1}, subject: {2}, e: {3}").format(to, fr, subject, e)$
由于您使用的是
“”“
,因此应在以下位置搜索术语“三重引号”

更改:

print """Exception when sending email to: {0},
        from: {1}, subject: {2}, e: {3}""".format(to, fr, subject, e)
print """Exception when sending email to: {0}, from: {1}, subject: {2}, e: {3}""".format(to, fr, subject, e)
print("""Exception when sending email \
to: {0}, \
from: {1}, \
subject: {2}, \
e: {3}""".format('to', 'fr', 'subject', 'e'))
Exception when sending email to: to, from: fr, subject: subject, e: e
至:

print """Exception when sending email to: {0},
        from: {1}, subject: {2}, e: {3}""".format(to, fr, subject, e)
print """Exception when sending email to: {0}, from: {1}, subject: {2}, e: {3}""".format(to, fr, subject, e)
print("""Exception when sending email \
to: {0}, \
from: {1}, \
subject: {2}, \
e: {3}""".format('to', 'fr', 'subject', 'e'))
Exception when sending email to: to, from: fr, subject: subject, e: e
编辑:

print """Exception when sending email to: {0},
        from: {1}, subject: {2}, e: {3}""".format(to, fr, subject, e)
print """Exception when sending email to: {0}, from: {1}, subject: {2}, e: {3}""".format(to, fr, subject, e)
print("""Exception when sending email \
to: {0}, \
from: {1}, \
subject: {2}, \
e: {3}""".format('to', 'fr', 'subject', 'e'))
Exception when sending email to: to, from: fr, subject: subject, e: e
如果需要保持行短,还可以使用
\
继续多行语句:

代码:

print """Exception when sending email to: {0},
        from: {1}, subject: {2}, e: {3}""".format(to, fr, subject, e)
print """Exception when sending email to: {0}, from: {1}, subject: {2}, e: {3}""".format(to, fr, subject, e)
print("""Exception when sending email \
to: {0}, \
from: {1}, \
subject: {2}, \
e: {3}""".format('to', 'fr', 'subject', 'e'))
Exception when sending email to: to, from: fr, subject: subject, e: e
输出:

print """Exception when sending email to: {0},
        from: {1}, subject: {2}, e: {3}""".format(to, fr, subject, e)
print """Exception when sending email to: {0}, from: {1}, subject: {2}, e: {3}""".format(to, fr, subject, e)
print("""Exception when sending email \
to: {0}, \
from: {1}, \
subject: {2}, \
e: {3}""".format('to', 'fr', 'subject', 'e'))
Exception when sending email to: to, from: fr, subject: subject, e: e
由于您使用的是
“”“
,因此应在以下位置搜索术语“三重引号”

更改:

print """Exception when sending email to: {0},
        from: {1}, subject: {2}, e: {3}""".format(to, fr, subject, e)
print """Exception when sending email to: {0}, from: {1}, subject: {2}, e: {3}""".format(to, fr, subject, e)
print("""Exception when sending email \
to: {0}, \
from: {1}, \
subject: {2}, \
e: {3}""".format('to', 'fr', 'subject', 'e'))
Exception when sending email to: to, from: fr, subject: subject, e: e
至:

print """Exception when sending email to: {0},
        from: {1}, subject: {2}, e: {3}""".format(to, fr, subject, e)
print """Exception when sending email to: {0}, from: {1}, subject: {2}, e: {3}""".format(to, fr, subject, e)
print("""Exception when sending email \
to: {0}, \
from: {1}, \
subject: {2}, \
e: {3}""".format('to', 'fr', 'subject', 'e'))
Exception when sending email to: to, from: fr, subject: subject, e: e
编辑:

print """Exception when sending email to: {0},
        from: {1}, subject: {2}, e: {3}""".format(to, fr, subject, e)
print """Exception when sending email to: {0}, from: {1}, subject: {2}, e: {3}""".format(to, fr, subject, e)
print("""Exception when sending email \
to: {0}, \
from: {1}, \
subject: {2}, \
e: {3}""".format('to', 'fr', 'subject', 'e'))
Exception when sending email to: to, from: fr, subject: subject, e: e
如果需要保持行短,还可以使用
\
继续多行语句:

代码:

print """Exception when sending email to: {0},
        from: {1}, subject: {2}, e: {3}""".format(to, fr, subject, e)
print """Exception when sending email to: {0}, from: {1}, subject: {2}, e: {3}""".format(to, fr, subject, e)
print("""Exception when sending email \
to: {0}, \
from: {1}, \
subject: {2}, \
e: {3}""".format('to', 'fr', 'subject', 'e'))
Exception when sending email to: to, from: fr, subject: subject, e: e
输出:

print """Exception when sending email to: {0},
        from: {1}, subject: {2}, e: {3}""".format(to, fr, subject, e)
print """Exception when sending email to: {0}, from: {1}, subject: {2}, e: {3}""".format(to, fr, subject, e)
print("""Exception when sending email \
to: {0}, \
from: {1}, \
subject: {2}, \
e: {3}""".format('to', 'fr', 'subject', 'e'))
Exception when sending email to: to, from: fr, subject: subject, e: e

字符串文字不需要在中间缩进。字符串文本不需要在中间缩进。我需要保持每行包含少于79个字符。更新我的答案…看一看。我需要保持每行包含少于79个字符。更新我的答案。。。看一看。