Skip to content Skip to sidebar Skip to footer

How To Break An Import Line In Python?

There are various questions about line continuations in python e.g. here, here and here, most pointing at the guidelines Continuation lines should align wrapped elements either ve

Solution 1:

If you're only importing 1 thing from the package, you should continue to do it the way that you currently are.

If you're importing multiple things, do something like this:

from package_name import (
    x,
    y,
    z,
)

Solution 2:

if you have :

from a.b.c.d.e import f

you can change this to :

from a.b.c.\
    d.e import f

Learnt this from a colleague of mine.


Post a Comment for "How To Break An Import Line In Python?"