1

Trying to re-factor codes by pep8.

Codes:

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

Output:

Exception when sending email to: to,
                from: fr, subject: subject, e: Invalid URL 'http//127.0.0.1:8000/'

How to remove the space before from in above output? Thanks

UPDATE

The following codes working fine. Should I delete this post?

 34             print ($
 35                 "Exception when sending email to: {0},"$
 36                 "from: {1}, subject: {2}, e: {3}").format(to, fr, subject, e)$
BAE
  • 8,550
  • 22
  • 88
  • 171

1 Answers1

0

Since you're using """, you should search for the term "triple-quotes" at this link.

Change:

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

To:

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

Edit:

If you need to keep your lines short, you can also use \ to continue the multi-line statement:

Code:

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

Output:

Exception when sending email to: to, from: fr, subject: subject, e: e
dot.Py
  • 5,007
  • 5
  • 31
  • 52