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.

Share:
10,635

Related videos on Youtube

LarsVegas
Author by

LarsVegas

SOreadytohelp

Updated on September 16, 2022

Comments

  • LarsVegas
    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 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?