Tkinter documentation is contradicting PEP8

南笙酒味 提交于 2019-12-02 01:26:15

问题


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.

Nonetheless the official documentation is contradicting:

to use Tkinter all you need is a simple import statement:

import tkinter

Or, more often:

 from tkinter import *

Is this a "documentation bug" ?


回答1:


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.



来源:https://stackoverflow.com/questions/48746351/tkinter-documentation-is-contradicting-pep8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!