Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The correct way to shorten long for statement to a maximum of 79 columns

My question is what's the most conventional way of making the following line of code:

self.steps = [setpoint_and_hold_time.setpoint for setpoint_and_hold_time in program.setpoints_and_hold_times]

to 79 character columns or less?

  • According to PEP8, the maximum line length should be 79 characters.
  • For long if statements I've used brackets but I'm not sure how I would use them here (if that's the solution).

Also, I assumed this line of code didn't need much background context, if it does please tell me and I'll edit in some classes that explain this line of code.

Thanks.

like image 356
ssp Avatar asked Dec 02 '22 11:12

ssp


1 Answers

black will reformat as (PEP8 compliant and it is quite readable I think):

self.steps = [
    setpoint_and_hold_time.setpoint
    for setpoint_and_hold_time in program.setpoints_and_hold_times
]
like image 96
Tiger-222 Avatar answered May 24 '23 05:05

Tiger-222