How to break long string lines for PEP8 compliance

2019-04-18 04:16发布

问题:

This question already has an answer here:

  • How to write very long string that conforms with PEP8 and prevent E501 8 answers

I have many long lines like this in the project and don't know how to break it to keep PEP8 happy. PEP8 shows warning from .format(me['id'])

pic_url = "http://graph.facebook.com/{0}/picture?width=100&height=100".format(me['id'])

How can I break the line to get rid of PEP8 warning and yet don't break the code?

回答1:

Using string literal concatenation:

pic_url = ("http://graph.facebook.com/{0}/"
           "picture?width=100&height=100".format(me['id']))