Vladimir Korshunov
Vladimir Korshunov

Reputation: 3090

PEP8 error in import line: E501 line too long

I have a python import string. PEP8 linter show to me E501 error line too long (82 > 79 characters):

from tornado.options import define, options, parse_config_file, parse_command_line

Solution with two line seems weird to me:

from tornado.options import define, options, parse_config_file
from tornado.options import parse_command_line

How I can fix it without disable E501 for this line?

Upvotes: 4

Views: 13494

Answers (3)

Aaron
Aaron

Reputation: 11075

You should write it the way you think is more readable.. the 80 column limit was put in place for old style terminals that did not support re-sizing, which itself was for legacy support of terminal only computers where the monitor was only 80 chars wide. See: A Foolish Consistency is the Hobgoblin of Little Minds #1 from pep8

Upvotes: 1

Henry Heath
Henry Heath

Reputation: 1082

See PEP 328 for your options. Parentheses are probably the way to go.

Upvotes: 2

Martijn Pieters
Martijn Pieters

Reputation: 1121924

Put your imported names in parentheses, letting you span multiple lines:

from tornado.options import (
    define,
    options,
    parse_config_file,
    parse_command_line,
)

Using one line per name has the added advantage that later edits to the list of names imported reduce line churn (you can see what was added and removed in your version control system as separate lines).

Upvotes: 14

Related Questions