A small question about PEP 8
Joshua Landau
joshua.landau.ws at gmail.com
Mon Jul 8 09:07:30 EDT 2013
On 8 July 2013 13:02, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> On Mon, 08 Jul 2013 11:39:21 +0100, Joshua Landau wrote:
> Imagine:
>>
>> """
>> a_wonderful_set_of_things = {
>> bannanas_made_of_apples,
>> chocolate_covered_horns,
>> doors_that_slide,
>> china_but_on_the_moon,
>> buffalo_with_windy_hair,
>> not_missing_an_end_brace
>> """¹
>>
>> Now, there are several places you can put the end brace. You can (be a
>> massive fool and) put it after the last item:
>>
>> """
>> a_wonderful_set_of_things = {
>> ...,
>> not_missing_an_end_brace}
>> """
>
> Well, call me a fool then, because when I have code that extends over
> *one* additional line, I prefer that:
>
> raise ValueError(
> "Some error message too long to fit on the above line")
>
> rather than:
>
> raise ValueError(
> "Some error message too long to fit on the above line"
> )
Fool.
>> You can also (be a fool and) put it at the same *indentation*:
>>
>> """
>> a_wonderful_set_of_things = {
>> ...,
>> not_missing_an_end_brace
>> }
>> """
>
> Call me a fool again, since I prefer this when there are more than one
> additional line. At least this time I'm in good company, since that's
> recommended by PEP 8.
Fool (less so, though).
>> Or you can (be sane) and put it at no indentation:
>>
>> """
>> a_wonderful_set_of_things = {
>> ...,
>> not_missing_an_end_brace
>> }
>> """
>
> I consider that the least aesthetically pleasing, and also rather awkward:
>
>
> some_result = some_function(
> arg1, arg2, arg3, arg4,
> [item1, item2, item3, item4,
> item5, item6, item7,
> item8, item9, item10,
> ],
> arg6, key=spam, word=eggs,
> extras=None, foo=bar,
> )
http://xkcd.com/605/
It was obvious¹ I was talking in context of my example. I used "no
indentation" because in that case "no indentation" was correct. If you
indent line #1, it follows that other lines might well be indented to
keep style consistent.
¹ I hope. I never suggested otherwise.
Since it's not too clear for you, my usage of fool was meant
pseudoironically as a subtle reminder that it's all subjective anyway,
but that I'm also still right.
More information about the Python-list
mailing list