Python script to fix long lines

When I run the nice tool ruff on my Python code, it often gives many “Line too long” warnings such as

pandas_util.py:81:89: E501 Line too long (90 > 88 characters)
pandas_util.py:241:89: E501 Line too long (98 > 88 characters)
pandas_util.py:302:89: E501 Line too long (110 > 88 characters)

As written on Stack Overflow

The preferred way of wrapping long lines is by using Python’s implied line continuation inside parentheses, brackets and braces.

Can someone suggest a Python script that does this when possible?

Depending on your IDE (and if you’re even using an IDE), you may have a ‘Reformatting’ tool, with options such as ‘Black’ or ‘PEP8’ for example, which should reformat long line, on-the-fly.

1 Like