简体   繁体   English

导入行中的PEP8错误:E501行太长

[英]PEP8 error in import line: E501 line too long

I have a python import string. 我有一个python导入字符串。 PEP8 linter show to me E501 error line too long (82 > 79 characters) : PEP8 linter向我显示E501错误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? 如何在不禁用此线路的E501的情况下修复它?

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). 每个名称使用一行具有额外的优势,即稍后编辑到导入的名称列表会减少行流失(您可以在版本控制系统中看到添加和删除的内容作为单独的行)。

See PEP 328 for your options. 有关您的选择,请参阅PEP 328 Parentheses are probably the way to go. 括号可能是要走的路。

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. 您应该按照您认为更具可读性的方式编写它。对于不支持重新调整大小的旧式终端,已经设置了80列限制,这本身仅用于仅支持80个字符的终端计算机的传统支持宽。 See: A Foolish Consistency is the Hobgoblin of Little Minds #1 from pep8 请参阅: 愚蠢的一致性是来自pep8 的小思想 #1的大地精

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM