23

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?

falsetru
  • 357,413
  • 63
  • 732
  • 636
Houman
  • 64,245
  • 87
  • 278
  • 460
  • 1
    Related: [How should I format a long url in a python comment and still be PEP8 compliant](http://stackoverflow.com/a/10740010/1014938) – Zero Piraeus Sep 20 '14 at 14:00

1 Answers1

31

Using string literal concatenation:

pic_url = ("http://graph.facebook.com/{0}/"
           "picture?width=100&height=100".format(me['id']))
falsetru
  • 357,413
  • 63
  • 732
  • 636
  • 11
    I don't know, as sourced in the comments, I don't thinking breaking a url into two lines is worth the PEP compliance. It makes both reading and editing it harder to do in the future. I think it's better to just let the line be too long. – Jared Goguen Mar 11 '16 at 01:52
  • 1
    @JaredGoguen, https://www.python.org/dev/peps/pep-0008/#a-foolish-consistency-is-the-hobgoblin-of-little-minds – falsetru Mar 11 '16 at 08:12