Search code examples
pythoncoding-stylepep8

In python, Does using long line without breaking into multiple line will affect speed or performance?


Currently, I am learning python and somewhere read; that if a line is too long, meaning more than 79 characters, the line should be split into a new line for readability.

Currently, I have all_fields variable which contains around 300 other model field variable. So all_fields variable is around 4000 characters long.

So If I split it multiple lines there will be too many lines and those lines look disturbing while reading or inspecting code Instead using it in one line looks good and improve readability.

So my question is:
Which method should I follow in such a scenario? Does it really recommend to split it in multiple lines because of guidelines? A single line with so many characters will affect my code performance or speed?

Thanks,


Solution

  • It's just a best practice so that others need not to scroll to see your code. Just one cool thing I have experinced with PyCharm IDE that this can be done automatically with IDE itself once you are done with code script writting. Probably, it may be a win-win choice. You wouldn't have to put any extra effort from your end to adhere with the best practices and reviewer will also enjoy reviewing it.