Tkinter 文档与 PEP 8 相矛盾
Tkinter documentation is contradicting PEP 8
PEP 8 states
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.
然而 official documentation 自相矛盾:
to use Tkinter all you need is a simple import statement:
import tkinter
Or, more often:
from tkinter import *
这是 "documentation bug" 吗?
我在这一点上提出了错误 issue 32830 并且共识(由 Python 核心开发人员达成)是尽管 from tkinter import *
确实违反了 PEP 8,但这是一个合理的例外,因为tkinter
"provides the enormous number of names (mostly constants like RIGHT or VERTICAL) which are convenient to use without prefix." 此外,PEP 8 指出 "do not break backwards compatibility just to comply with this PEP!" 并且由于 tkinter 目前经常以这种方式导入,因此这种观点适用于此。
PEP 8 states
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.
然而 official documentation 自相矛盾:
to use Tkinter all you need is a simple import statement:
import tkinter
Or, more often:
from tkinter import *
这是 "documentation bug" 吗?
我在这一点上提出了错误 issue 32830 并且共识(由 Python 核心开发人员达成)是尽管 from tkinter import *
确实违反了 PEP 8,但这是一个合理的例外,因为tkinter
"provides the enormous number of names (mostly constants like RIGHT or VERTICAL) which are convenient to use without prefix." 此外,PEP 8 指出 "do not break backwards compatibility just to comply with this PEP!" 并且由于 tkinter 目前经常以这种方式导入,因此这种观点适用于此。