Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a number of classes / functions to import from a module and linters/ style checkers (pylint, flake, pep8) are complaining that the line is too long and I am forced to use line continuation which is ugly:

from my_lengthy_module import FirstClass, SecondClass, ThirdClass,   
foo_bar_with_long_name, bar_foo_with_longer_name, 
FourthClass, bar_foo_with_longer_name, foo_bar_with_longest_name

How to do it better?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
147 views
Welcome To Ask or Share your Answers For Others

1 Answer

Python 2.5 introduced a concept of multi-line imports (PEP-328) which address this problem by extending the syntax of the import statement to include the imported names in brackets and thus avoiding line continuations:

from my_lengthy_module import (
    FirstClass, SecondClass, ThirdClass, 
    foo_bar_with_long_name, bar_foo_with_longer_name,
    FourthClass, bar_foo_with_longer_name, foo_bar_with_longest_name
)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...