为什么要导入带括号的语句?

2024-06-28 20:44:50 发布

您现在位置:Python中文网/ 问答频道 /正文

最近有这样的进口货

from module import (function, another_function, 
                    another_function)

似乎这样做是为了能够将import语句扩展到多行。在这种情况下,我通常只是这样导入

from module import function, another_function, \
            another_function

在这种情况下括号到底在做什么?它们被认为是不好的做法吗?


Tags: fromimportanother情况function语句括号module
1条回答
网友
1楼 · 发布于 2024-06-28 20:44:50

作为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.

相关问题 更多 >