Why import statements with parentheses?

PythonImportParentheses

Python Problem Overview


Lately have seen imports like this

from module import (function, another_function, 
                    another_function)

Seemingly this has been done to be able to stretch the import statement over more than one line. In cases like this I usually just import like so

from module import function, another_function, \
            another_function

What exactly are the parentheses doing in this case and are they considered to be bad practice?

Python Solutions


Solution 1 - Python

As PEP 8 states:

> The preferred way of wrapping long lines is by using Python's implied line continuation inside parentheses, brackets and braces. Long lines can be broken over multiple lines by wrapping expressions in parentheses. These should be used in preference to using a backslash for line continuation.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionLarsVegasView Question on Stackoverflow
Solution 1 - PythondecezeView Answer on Stackoverflow