2017-04-18 6 views
0

pep8でコードを再構築しようとしています。Python:複数行の出力形式のスペース

コード:

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の前にスペースを削除するには?おかげ

UPDATE

細かい作業を以下のコード。この投稿を削除する必要がありますか?

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を検索する必要があります。

変更:

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 
+1

79文字未満の各行を保持する必要があります。 – BAE

+0

私の答えを更新しました。 –