11

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?

Community
  • 1
  • 1
doctorlove
  • 18,872
  • 2
  • 46
  • 62
  • 2
    how about putting parenthesis around the items. that way you can format however you like? – Kenji Noguchi Feb 02 '17 at 19:28
  • 1
    Short answer: No. Research effort: [here](https://www.google.com/search?client=ubuntu&channel=fs&q=python+import+statement+line+continuation&ie=utf-8&oe=utf-8), then [here](https://www.python.org/dev/peps/pep-0328/) – dsh Feb 02 '17 at 19:31
  • It didn't occur to me to search for *multi-line* imports. I have learnt something though – doctorlove Feb 02 '17 at 19:38

2 Answers2

18

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,
)
Harrison
  • 5,095
  • 7
  • 40
  • 60
4

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.

Jayanth
  • 115
  • 1
  • 11