Home python Transfer long lines of code with a point, as correctly by PEP8

Transfer long lines of code with a point, as correctly by PEP8

Author

Date

Category

The question arose, how to properly and beautifully make the transfer of the long line of the PEP8 code at the point point:

result = list (
  MyModel.Objects.
    .Filter (field1 = 100)
    .exClude (field2 = 'a')
    .Values_List (Field3, Flat = True))

Trying to do so, inserting indents at the beginning of each row before the point. But AutoPep8 reformat:

result = list (
  MyModel.Objects.
  .Filter (field1 = 100)
  .exClude (field2 = 'a')
  .Values_List (Field3, Flat = True))

everything would be nothing, but this is the code over which the team works and it requires a single stylist. Or justify why you need to change it. I tried to search and did not find anything. And yes, the first option seems to me more understandable and readable. But if PEP8 really requires formatting option 2, then what, you need to follow it. Yes, and simply when saving, constant reformatting occurs, and then before the committees in the repository it is removed – extra costs.


Answer 1, Authority 100%

I think in such cases I consider the most readable option at which the first piece with a point goes from a new line:

result = list (
  MYMODEL.
  .Objects.
  .Filter (field1 = 100)
  .exClude (field2 = 'a')
  .Values_List (Field3, Flat = True)
  )

There is no extra indentation and auto-checking style does not swear.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions