Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
每当我使用星号 ( from <anymodule> import *) 从另一个模块导入时,我都会收到“未使用的野生导入”警告。似乎这不是进行导入的正确方法,但是如果我们不应该使用它,为什么还要存在这种语法呢?
from <anymodule> import *
该消息只是告诉您您正在从不需要的模块中导入功能,这意味着您可能应该只导入您需要的东西。你应该简单地使用你真正from foobar import x, y需要x的y元素。
from foobar import x, y
x
y
from foobar import *当您不想考虑或键入更多字符而没有什么好处时,该语法在命令行解释器中更有用。但是在实际项目中,您不应该使用该语法,因为如果您使用它,将不清楚您将使用模块中的哪个功能。
from foobar import *