Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to break long string lines for PEP8 compliance? [duplicate]

Tags:

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?

like image 841
Houman Avatar asked Sep 20 '14 13:09

Houman


People also ask

How do you break a long string into multiple lines?

Long strings can be written in multiple lines by using two double quotes ( “ “ ) to break the string at any point in the middle.

How do you break a long string in Python?

Use a backslash ( \ ) as a line continuation character In Python, a backslash ( \ ) is a line continuation character. If a backslash is placed at the end of a line, it is considered that the line is continued on the next line.

How do you print long statements in Python?

The preferred way of wrapping long lines is by using Python's implied line continuation inside parentheses, brackets and braces. If necessary, you can add an extra pair of parentheses around an expression, but sometimes using a backslash looks better. Make sure to indent the continued line appropriately.

How do you continue an if statement on the next line in Python?

You cannot split a statement into multiple lines in Python by pressing Enter . Instead, use the backslash ( \ ) to indicate that a statement is continued on the next line.


1 Answers

Using string literal concatenation:

pic_url = ("http://graph.facebook.com/{0}/"            "picture?width=100&height=100".format(me['id'])) 
like image 115
falsetru Avatar answered Oct 25 '22 10:10

falsetru