Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I break an import line in Python?

Tags:

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 vertically using Python's implicit line joining inside parentheses, brackets and braces, or using a hanging indent

Most of the specifics are around a long if statement, which can use parenthesis or implicit continuations if calling a function.

This begs the question, how should you deal with import statements? Specifically, what else can I do with

from concurrent.futures import \
  ProcessPoolExecutor

Is a line continuation my only option?

like image 516
doctorlove Avatar asked Jan 23 '26 02:01

doctorlove


1 Answers

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,
)
like image 55
Harrison Avatar answered Jan 24 '26 19:01

Harrison