Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why import statements with parentheses? [duplicate]

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?

like image 851
LarsVegas Avatar asked Apr 09 '15 08:04

LarsVegas


1 Answers

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.

like image 72
deceze Avatar answered Oct 21 '22 11:10

deceze