Python function argument list formatting

Viewed 67340

What is the best way to format following piece of code accordingly to PEP8:

oauth_request = oauth.OAuthRequest.from_consumer_and_token(consumer,
    token=token, verifier=verifier, http_url=ACCESS_TOKEN_URL)

The problem is that if I place more than one parameter on the first line, the line exceeds 79 characters. If I place each of the parameters on a separate line with 4 spaces indentation it looks quite ugly:

oauth_request = oauth.OAuthRequest.from_consumer_and_token(
    consumer,
    token=token,
    verifier=verifier,
    http_url=ACCESS_TOKEN_URL)

The best option that I come up with is to add extra indentation for better distinguishing:

oauth_request = oauth.OAuthRequest.from_consumer_and_token(
                        consumer,
                        token=token,
                        verifier=verifier,
                        http_url=ACCESS_TOKEN_URL)

I try to work out a general rule for me to use it for methods with long invocation on the first line and several parameters that can't fit a single line.

1 Answers
Related