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

标签 python import parentheses

最近看到这样的导入

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/

相关文章:

javascript - 如何在 WebStorm 中转义括号?

带/不带括号的 Javascript 函数调用

python - 如何使用 Python 检查 SQLite 中是否存在一行?

python - 从 Pandas DataFrame 中提取数组(列名、数据)

Python - 检查字母是否出现在连续的单词中

python - 简化这个 Django 查询

java - 如何在 Eclipse 中将 Lanterna 包导入到 Java

css - 无法在 Django 模板中加载字体

python - 将模块(特别是 pymorph)添加到 Spyder(Python IDE)

php - PHP 中的正则表达式。获取第一级括号之间的文本