编程语言
首页 > 编程语言> > python-Tkinter文档与PEP8矛盾

python-Tkinter文档与PEP8矛盾

作者:互联网

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 *

这是“文档错误”吗?

解决方法:

我在这一点上提出了错误issue 32830,并且(Python核心开发人员达成的共识)是,尽管from tkinter import *确实违反了PEP 8,但这是一个合理的例外,因为tkinter“提供了大量名称(主要是常量,例如RIGHT或垂直),无需前缀即可使用.”此外,PEP 8声明“不要为了遵守此PEP而破坏向后兼容性!”由于tkinter目前经常以这种方式导入,因此这种观点在这里适用.

标签:python,tkinter,coding-style,pep8
来源: https://codeday.me/bug/20191011/1889543.html