Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deal with Python long import

This is about python long import like this:

from aaa.bbb.ccc.ddd.eee.fff.ggg.hhh.iii.jjj.kkk.lll.mmm.nnn.ooo import xxx

The length between 'from' and 'import' is already above than 80 characters, is there any better pythonic ways to deal with it?

like image 434
Eric Avatar asked Oct 18 '22 01:10

Eric


1 Answers

You can always wrap lines using the \ character at the end of the line.

from a.very.long.and.unconventional.structure.\
         and.name import foo

For multiple statements to import after the from x import statement, you can use parentheses and wrap inside these parentheses without a newline escape:

from foo.bar import (test,
                     and,
                     others)
like image 122
languitar Avatar answered Oct 21 '22 04:10

languitar