Why import statements with parentheses?
10,635
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.
Related videos on Youtube
Comments
-
LarsVegas over 1 year
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 sofrom module import function, another_function, \ another_function
What exactly are the parentheses doing in this case and are they considered to be bad practice?
-
jonrsharpe about 9 years
-