尝试通过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/'
如何删除上述输出中from
之前的空格?感谢
更新
以下代码正常运行。我应该删除这篇文章吗?
34 print ($
35 "Exception when sending email to: {0},"$
36 "from: {1}, subject: {2}, e: {3}").format(to, fr, subject, e)$
答案 0 :(得分:0)
由于您使用的是"""
,因此您应该在this link搜索“triple-quotes”一词。
更改:强>
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