Tkinter文档与PEP8相矛盾 [英] Tkinter documentation is contradicting PEP8
问题描述
PEP 8 状态
通配符导入(来自import *)应避免,因为它们不清楚名称空间中存在哪些名称,这会混淆读者和许多自动化工具。
Wildcard imports (from import *) should be avoided, as they make it unclear which names are present in the namespace, confusing both readers and many automated tools.
尽管如此,官方文档相互矛盾:
要使用Tkinter,您需要的只是一个简单的导入语句:
to use Tkinter all you need is a simple import statement:
import tkinter
或更常见的是:
Or, more often:
from tkinter import *
这是文档错误吗?
推荐答案
我提出了错误问题32830 在这一点上(Python核心开发人员已达成共识)是,尽管 tkinter
提供了大量易于使用的名称(主要是诸如RIGHT或VERTICAL之类的常量)没有前缀。此外,PEP 8声明不要为了遵守此PEP而破坏向后兼容性!而且由于tkinter目前经常以这种方式导入,因此这种观点在这里适用。
I raised bug issue 32830 on this point and the consensus (reached by Python core developers) is that although the from tkinter import *
does violate PEP 8, this is a reasonable exception because tkinter
"provides the enormous number of names (mostly constants like RIGHT or VERTICAL) which are convenient to use without prefix." Additionally, PEP 8 states "do not break backwards compatibility just to comply with this PEP!" and since tkinter is frequently imported in this way currently, this sentiment applies here.
这篇关于Tkinter文档与PEP8相矛盾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!