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)$ 
1
  • String literals don't need to be indented in the middle. Commented Apr 18, 2017 at 20:17

1 Answer 1

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 
Sign up to request clarification or add additional context in comments.

2 Comments

I need to keep each line containing less than 79 chars.
Updated my answer... take a look.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.