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.
我正在尝试编写我的第一个 Python 包,几乎我所有的模块都需要使用 NumPy。我应该import numpy在每个模块中编写还是在包中的某个地方我可以只导入一次以便每个模块都可以使用它?最好的方法是什么?
import numpy
是的,只要在需要的地方导入它。
不要太聪明地编写为您导入所有内容的函数或为您导入内容并从中导入内容的元模块import *;所有这些只会使您的代码难以阅读,并且只是发生错误的另一个地方。
import *