最近看到这样的导入
from module import (function, another_function,
another_function)
似乎这样做是为了能够将 import
语句延伸超过一行。在这种情况下,我通常只是这样导入
from module import function, another_function, \
another_function
在这种情况下,括号究竟在做什么,它们是否被认为是不好的做法?
最佳答案
作为 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.
关于python - 为什么要导入带括号的语句?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29534027/