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.
You can send any data types of argument to a function (string, number, list, dictionary etc.), and it will be treated as the same data type inside the function.
5 Types of Arguments in Python Function Definition:positional arguments. arbitrary positional arguments. arbitrary keyword arguments.
In Python, you can unpack list , tuple , dict (dictionary) and pass its elements to function as arguments by adding * to list or tuple and ** to dictionary when calling function.
list() Parameters. The list() constructor takes a single argument: iterable (optional) - an object that could be a sequence (string, tuples) or collection (set, dictionary) or any iterator object.
My reading of the documentation suggests that 2 and 3 are both acceptable, but it looks like 2 is preferred (I say this because it looks like 2 vs. 3 is handled this way in the examples, I don't think that the style specification is very specific here). 1 is out (look at the docs under the line Arguments on first line forbidden when not using vertical alignment
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With